使用大小优化(-Os)编译 boost_regex 时出现“重复部分”错误

2023-11-26

编译器: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

boost: 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

code:

#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

error:

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开关清除了错误,但应用程序大小是原来的 2 倍。

也许我也应该构建具有大小优化的 Boost,但我不知道在 b2 命令行中传递此选项的位置。


就我而言,boost 1.58 是使用“-march=i686”进行内部编译的,但我的代码不是。将“-march=i686”添加到我的项目中消除了所有“重复部分”。

经验教训:始终煞费苦心地确保所有库和主项目都使用相同的编译器选项进行编译。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用大小优化(-Os)编译 boost_regex 时出现“重复部分”错误 的相关文章

随机推荐