11

编译器: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开关会清除错误,但应用程序大小会大 2 倍。

也许我也应该使用大小优化来构建 Boost,但我不知道在 b2 命令行中将这个选项传递到哪里。

4

3 回答 3

15

在我的情况下,boost 1.58 是使用“-march=i686”在内部编译的,但我的代码不是。在我的项目中添加“-march=i686”消除了所有“重复部分”。

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

于 2015-04-19T22:27:46.203 回答
3

我相信这是一个编译器错误。在我的情况下,解决方法是添加-fno-tree-vectorize.

于 2014-06-15T19:37:04.023 回答
0

当我在 MinGW32 中使用 gcc-4.9.1 和一个使用 gcc-4.4.7 作为编译器的库编译我的代码时,我遇到了同样的错误。而且我也用ccache来加速,ccache也是个问题。删除 ~/.ccache/ 中的缓存并重新编译,然后我解决了这个问题。

于 2015-11-17T08:57:45.797 回答