Boost linking error: 'B5cxx11' symbols missing

元气小坏坏 提交于 2020-01-14 13:57:48

问题


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).


回答1:


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).




回答2:


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.




回答3:


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



来源:https://stackoverflow.com/questions/35562604/boost-linking-error-b5cxx11-symbols-missing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!