1

I've written the following groundbreaking application:

#include <boost/program_options.hpp>
int main(int argc, char** argv)
{
    boost::program_options::options_description generic_options("foo");
    return 0;
}

I am trying to build this on Debian Stretch, on which the default compiler is GCC 5.3.1-5, and the installed version of Boost is 1.58.0.

However, for reasons which I will not go into here (which would be apparent had this not been a MCVE), I need to compile and link the binary using g++-4.9, not g++-5.3. Compiling works fine, but when I try to link, this is what happens:

/usr/bin/g++-4.9   -Wall -std=c++11   CMakeFiles/tester3.dir/src/altmain2.cpp.o  -o bin/tester3 -rdynamic -lboost_log -lboost_system -lboost_program_options 
CMakeFiles/tester3.dir/src/altmain2.cpp.o: In function `main':
altmain2.cpp:(.text+0x61): undefined reference to `boost::program_options::options_description::options_description(std::string const&, unsigned int, unsigned int)'
  • Is this due to some ABI incompatibility between gcc 4 and 5?
  • If so, is there any way to get around it other than building my own version of Boost?
  • If not, what could cause this?
Community
  • 1
  • 1
einpoklum
  • 118,144
  • 57
  • 340
  • 684
  • does it work when you build boost using gcc-4? also have a look at http://developerblog.redhat.com/2015/02/05/gcc5-and-the-c11-abi/ – m.s. Jan 24 '16 at 14:11
  • @m.s.: My gcc-4 is gcc-4.9 and that's what doesn't work. – einpoklum Jan 24 '16 at 14:52

1 Answers1

3

Is this due to some ABI incompatibility between gcc 4 and 5?

Looks like it is. By default GCC 5 uses a new ABI for several important standard library classes, including std::basic_string template (and thus also std::string). Unfortunately it would be impossible to make std::string fully conform to C++11 and later without breaking the ABI.

libstdc++ implements dual ABI, so that binaries compiled with older versions of GCC will link (and work correctly) with the new library. See this post by Jason Merrill (the maintainer of GCC's C++ front end) for details.

If so, is there any way to get around it other than building my own version of Boost?

Probably not. Boost depends on the new implementation of std::string and does not provide backward compatibility (unlike libstdc++). This problem is mentioned in Debian bugtracker.

Mikhail Maltsev
  • 1,632
  • 11
  • 21
  • I would think the distribution should then provide at least some central C++ libraries in the old ABI as well - as optional packages at least. Anyway, +1 for the answer but no accept in case someone can offer some kind of workaround. – einpoklum Jan 24 '16 at 16:27
  • Mikhail, am I to understand that only an older version of boost would help me? – einpoklum Jan 30 '16 at 09:51
  • 1
    No, you can recompile any version of Boost with GCC 4.9 and it should work fine. – Mikhail Maltsev Jan 30 '16 at 09:56