微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

当编译具有大小优化(-Os)的boost_regex时,我收到“重复部分”错误

编译器: http://sourceforge.net/projects/mingwbuilds/files/host-windows/releases/4.7.2/32-bit/threads-posix/sjlj/x32-4.7.2-release-posix-sjlj-rev6.7z

提升:http://sourceforge.net/projects/boost/files/boost/1.52.0/boost_1_52_0.7z

(D:驱动器上)

boost_regex编译为:

b2 --prefix=D:\boost toolset=gcc --with-regex --layout=tagged release

码:

#include <boost\regex.hpp>
int main() {
  boost::regex reg("[a-z]+");
}

编译参数:

g++ -I "d:\boost" -Os -o test.exe test.cpp -static -L d:\boost\stage\lib -lboost_regex-mt

错误

d:\boost\stage\lib\libboost_regex-mt.a(regex.o): duplicate section `.rdata$_ZTVN5boost16exception_detail19error_info_injectorISt13runtime_errorEE[__ZTVN5boost16exception_detail19error_info_injectorISt13runtime_errorEE]' has different size
d:\boost\stage\lib\libboost_regex-mt.a(regex.o): duplicate section `.rdata$_ZTVN5boost16exception_detail10clone_implINS0_19error_info_injectorISt13runtime_errorEEEE[__ZTVN5boost16exception_detail10clone_implINS0_19error_info_injectorISt13runtime_errorEEEE]' has different size
d:\boost\stage\lib\libboost_regex-mt.a(regex.o): duplicate section `.rdata$_ZTSN5boost16exception_detail10clone_implINS0_19error_info_injectorISt13runtime_errorEEEE[__ZTSN5boost16exception_detail10clone_implINS0_19error_info_injectorISt13runtime_errorEEEE]' has different size
d:\boost\stage\lib\libboost_regex-mt.a(regex.o): duplicate section `.rdata$_ZTSN5boost16exception_detail10clone_baseE[__ZTSN5boost16exception_detail10clone_baseE]' has different size
d:\boost\stage\lib\libboost_regex-mt.a(regex.o): duplicate section `.rdata$_ZTSN5boost16exception_detail19error_info_injectorISt13runtime_errorEE[__ZTSN5boost16exception_detail19error_info_injectorISt13runtime_errorEE]' has different size

它编译好,但是我还没有测试它是否会在更复杂的代码中工作.删除-Os开关清除错误,但应用程序大小是两倍.

也许我应该使用大小优化构建Boost,但是我不知道在b2命令行中通过此选项的位置.

解决方法

在我的情况下,boost 1.58内部编译为“-march = i686”,但是我的代码没有.将“-march = i686”添加到我的项目中,摆脱了所有的“重复部分”.

经验教训:总是精心确保所有库和主项目都使用相同的编译器选项进行编译.

原文地址:https://www.jb51.cc/c/112035.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐