使用gcc 5 编译c++11编写的程序 出现的符号找不到的链接问题。

本文介绍了使用GCC5.2编译C++11程序时遇到的链接错误问题及解决方法。当链接到非C++11编写的静态库时,可能会出现符号未定义的错误,即使这些符号实际上存在于静态库中。文章提供了如何通过设置宏来解决这个问题的具体步骤。

记录今天遇到的问题:


1. 使用c++11 写了一段c++程序,使用gcc 5.2编译。程序引用了非c++11编写的静态库

2. 链接时总是报某个函数找不到 但是使用nm命令查看,符号确实存在



经过google发现,原来gcc 5引入了新的ABI



https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_dual_abi.html


If you get linker errors about undefined references to symbols that involve types in the std::__cxx11 namespace or the tag [abi:cxx11] then it probably indicates that you are trying to link together object files that were compiled with different values for the _GLIBCXX_USE_CXX11_ABI macro. This commonly happens when linking to a third-party library that was compiled with an older version of GCC. If the third-party library cannot be rebuilt with the new ABI then you will need to recompile your code with the old ABI.


对于我的问题,需要在参数上增加 -D_GLIBCXX_USE_CXX11_ABI=0 就解决了。

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值