r/cpp • u/TheRavagerSw • Oct 15 '26
Please consider bundling C++ STL with your application
Systems targeted by C++ toolchains vary a lot even though C++ constantly changes. If you rely on operating system STL for your application code, following things may happen:
If your platform A supports C++20 and your platform B supports C++14 and your platform C supports C++11, you will either force C++ <= 11 to all your libraries, or use macro magic etc, to use one set of features each platform.
If you operate in a specialized domain, such as real-time systems, you may need a standard library built with specific configuration options, such as disabling exceptions or RTTI. Relying on the system-provided STL leaves you dependent on how it was built, which may not meet your requirements
If you build your STL of choice you solve all these issues:
- You can use the highest C++ standard possible, you no longer have to think about each operating system state extensively.
- You can configure your STL to match your needs
In nearly all modern system languages you build standard library yourself, I don't see any reason why C++ developers shouldn't consider this.
13
u/DnBenjamin Oct 15 '26
I have no idea what any of this means. Do you want me to write my own implementation of the C++ standard library and maintain it on every platform I want to target instead of using MSVC STL, libstdc++, libc++, etc.?
4
u/jwezorek Oct 16 '26
I don't understand why you're presenting this as general advice for C++ application developers.
Much of the standard library is implemented in headers/templates and compiled into the application already. For the parts that aren't, developers can statically link the implementation supplied with their compiler.
I can see why building your own libc++ might be useful if it is solving some problem in a cross-platform development scenario but a lot of C++ development is either not cross-platform or is trivially cross-platform. Consider someone writing a Windows application that is already using DirectX etc. so is already only targeting Windows. What problem would building libc++ rather than just using Microsoft's standard library solve?
It seems like you are describing a solution to some specific deployment or toolchain problem but treating it like the specific requirements of that case apply generally.
5
u/neppo95 Oct 15 '26
There's reasons why you don't even want to do this whilst being irrelevant for a lot of projects altogether. As for "nearly all modern system languages you build standard library yourself" -> That is just false. Don't spread misinformation.
3
u/holyblackcat Oct 17 '26
.sofrom the driver gets loaded into your app, and it wants libstdc++. The one I bundled was older, so it broke. You need some clever script that analyzes what version is available at runtime, and choses between it and yours usingLD_LIBRARY_PATH.20
u/ybungalobill Oct 15 '26
You are conflating STL with C++ runtime, they are not the same.
Every application under the sun bundles STL with its binaries because STL is a Standard *Template* Library and templates are instantiated and linked with your executable...
1
u/nzmjx Oct 15 '26
You cannot bundle STL with your application because it is part of standard. And you cannot build standard library with your application, because it is neither portable nor supported.
It is done this way: you target specific standard version, and if there is something available from more recent version in the library (which is not a language feature) you conditionally use it while providing fallback implementation.
1
u/stick_figure Oct 15 '26
I think this is correct. Both go and rust link statically by default (to different degrees), and you never ask yourself "will this go binary run on that target Linux system?" because you just know it will.
Modern developers should really see dynamic linking and plugin loading into the same process address space as advanced use cases, and process address space isolation and IPC as the default level of separation for code that is built separately by different people and parties.
Back in the 90s, DLLs probably made a lot of sense when you're shooting to hit certain performance and memory usage targets, but with AI and everything else going on, you want to optimize to minimize coordination overhead so you can have fritctionless fast upgrades. That means more isolation, more hermeticity between separately compiled components.
0
u/UndefinedDefined Oct 16 '26
Another choice is to not use it - then there is no problem linking to it or just linking it statically.
0
u/13steinj Oct 15 '26
First time I see a post from you in a while and I just say "based take no notes."
For reference, Plex is a great example of a C++ application that does this. Weirdly it's the only one I can think of that does this on Linux platforms, and I don't know why. I guess in fairness most applications just rely on flatpak or separate deb/rpm maintainers instead, and I don't know why.