4

Here's the issue: the code I'm using uses a big library which links against boost. When I compile with static linking, everything works fine. However, when I try dynamic linking I get a bunch of undefined reference errors. The first thought was obviously "I am not linking the boost program_options" library, but I looked, and it is there in the linking command (and it comes after the library that needs it). Among the different errors, though, this stood out:

undefined reference to `_ZN5boost15program_options3argB5cxx11E

In my daily experience, linking errors are usually of the form "undefined reference to somefunction(...)". So I went to the installation folder of my boost library and used readelf to see what symbols I have in the library libboost_program.so. And in fact, that symbol does not appear. Instead, the closest I found is _ZN5boost15program_options3argE.

Google-ing a little bit, I found out that the extra part B5cxx11 is a new addition to the name mangling since C++11. It appears that boost (at least version 1.59.0) does not yet support this new name mangling.

So my question is: Is this a known issue? What workaround are there? And why does this issue not show up with static linking?

Edit: In case someone stumbles on this question in the future, I just tried boost 1.60.0, and the symbols contain the string B5cxx11. I believe (read: hope) this will solve the issue. As a double check, though, I am going to recompile again boost 1.59.0 to see if this is due to something I changed in my environment (although I doubt it).

bartgol
  • 1,703
  • 2
  • 20
  • 30

3 Answers3

1

This question was asked many moons ago, but since I already landed on this page I will pitch in with a possible solution.

You could try to compile your code with the -D_GLIBCXX_USE_CXX11_ABI=0 flag or define this macro: #define _GLIBCXX_USE_CXX11_ABI 0. See answers for this question for more details.

0

It's not that boost has to support it, your compiler/linker has. Probably your library was compiled with C++11 support and so was your boost, but your current program isn't. Try with the --std=c++11 option if you're on GCC.

Or maybe it's the other way around, and you're instantiating a template in your C++11 which uses C++11 name mangling and can't find library functions in the non-C++11-compiled boost (though that would border on compiler bug).

Marcus Müller
  • 34,677
  • 4
  • 53
  • 94
  • The executable should be compiled with `--std=c++11`, since it uses some of those features and I never got a complaint. Also, the flag should be already inherited from the linked libraries, via cmake. But I'll try adding it explicitly and see what happens. – bartgol Feb 22 '16 at 20:00
  • Uh, I checked and I was already explicitly telling cmake to add that flag to the already existing cxx flags... – bartgol Feb 22 '16 at 21:44
0

I have a similar problem recently. I recompile my boost library using the following commands

./b2 --build-dir=build/x86 address-model=32 threading=multi --toolset=gcc --layout=versioned --stagedir=./stage/x86 -j 8

./b2 --build-dir=build/x64 address-model=64 threading=multi --toolset=gcc --layout=versioned --stagedir=./stage/x64 -j 8

Then compile my program using

g++ main.cpp -L/home/research/boost_library/boost_1_68_0/stage/x64/lib/ -lboost_program_options-gcc82-mt-x64-1_68

This solves my problem. I am using gcc 8.2 on redhat linux

user11594134
  • 119
  • 8