Recently, I saw a C++ program list both libstdc++ and libc++ in its dynamic section (readelf -d
).
I’m confused because one is from GNU and the other from LLVM and they are both implementations of the STL. Then how can a program link both? What’s that mean?
How does it resolve a symbol (std::string
, for example) that both provide, when linking?
This might for example happen if a program links with one standard-library implementation and also with a static library that links to the other. This wouldn’t cause an issue because names such as std::string
are mangled into something longer and more complicated that won’t clash. (This is also how functions with the same name can be overloaded and called with different argument types, and why programs written for older versions of the standard library don’t break when it’s upgraded.)
One important caveat: this only works if the STL is not part of the interface of any component that links to a different version. Otherwise, any client code will compile against a different version of the standard library than it links to when it calls that component, or even pass the wrong data structures to and from the library.