在G ++ 4.9 - - 5上下的分配使用G ++与升压链接时未定义参考 [英] Undefined reference when linking with Boost using g++-4.9 on a g++-5-ish distribution
问题描述
我已经写了下面的突破性应用程序:
的#include<升压/ program_options.hpp>
INT主(INT ARGC,字符** argv的)
{
提高:: program_options :: options_description GENERIC_OPTIONS(富);
返回0;
}
我想建立这个在Debian平伸,在其默认的编译器是gcc 5.3.1-5和安装的加速的版本是1.58.0。
然而,对于我不会去到这里的原因(其中would很明显过这种没有经过MCVE),我需要编译和链接使用二进制 G ++ - 4.9
,而不是 G ++ - 5.3
。编译工作正常,但是当我尝试链接,这是发生了什么:
的/ usr / bin中/ G ++ - 4.9 -Wall -std = C ++ 11 CMakeFiles / tester3.dir / src目录/ altmain2.cpp.o -o斌/ tester3 -rdynamic - lboost_log -lboost_system -lboost_program_options
CMakeFiles / tester3.dir / src目录/ altmain2.cpp.o:在函数'主':
。altmain2.cpp :(文字+ 0x61):未定义的引用`的boost :: program_options :: options_description :: options_description(标准::字符串常量和放大器;,为unsigned int,unsigned int类型)
- 这是由于GCC 4和5之间的一些不兼容ABI?
- 如果是这样,有什么办法来解决它比建设自己的Boost版本等?
- 如果没有,这是什么原因?
这是由于一些不兼容ABI GCC 4和5之间?
块引用>看起来是。默认情况下GCC 5采用了新ABI几个重要的标准库类,包括
的std :: basic_string的
模板(也因此而的std ::字符串
)。不幸的是这将是不可能做出的std ::字符串完全符合C ++ 11后来没有打破ABI。++的libstdc实现双ABI,使之与旧版本的GCC编译的二进制文件将链接(和正常工作)与新库。看到这个后通过贾森美林(中GCC的C ++前端)的详细信息的维护者。
如果是这样,有什么办法解决它除了建设自己的
升压的版本?
块引用>大概不会。升压依赖于新的实现字符串的
的std ::并且不提供向后兼容性(不像的libstdc ++)。这个问题是 Debian中提到的错误追踪系统。
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
, notg++-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?
解决方案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 alsostd::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.这篇关于在G ++ 4.9 - - 5上下的分配使用G ++与升压链接时未定义参考的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!