Search code examples
c++booststatic-linkingdynamic-linkinglibstdc++

C++ STL Versioning Issue + Boost


I've been building a C++ library that I want to distribute as a single.so file to my users, and hopefully have that .so file be, for the most part, distro agnostic. Thus, I've been linking 3rd party libraries statically (but still dynamically linking to the standard library)

Right now it builds fine with g++ on CentOS 6.2 (64 bit), but it is having issues building on CentOS 5.3. Compilation goes through fine, but I get a linker error:

cpu_timer.cpp:(.text+0x288): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::basic_ostream<char, std::char_traits<char> >::_M_insert<long double>(long double)'

I've done some searching on the error and it seems to be an issue with versioning of the standard library itself. My code, or rather boost::thread's code, is trying to make a call to a newer version of something that doesn't exist in the standard library included on CentOS 5.3.

Understandable. So I need to either:

  • Link statically against the C++ standard library (I've done some research about this and it is a huge pain on 64 bit systems. The libstdc++.a included with most 64 bit systems is not built with -fPIC, and -fPIC is actually a necessity to do static linking on 64 bit systems. I would have to actually build libstdc++.a myself. Ugh...
  • Revert boost::timer to some more compatible version. I'm mostly using it for portable mutexes, so I'm not in any need of bleeding-edge boost::thread features. But this comes with its own issue: Where on the boost website do they document their dependencies to the standard library (and which versions). Do they document it at all? I can't seem to find the information. Also, is this a wise choice? What other nasty surprises could the standard library have for me?

Given my goal (as close to distro agnostic as possible), which route would you recommend?


Solution

  • I'd say use a version of Boost that's old enough to be compatible with all the distros you want it to be compatible with.