I got 'duplicate section' errors when compiling boost_regex with size optimization (-Os)

▼魔方 西西 提交于 2019-12-30 03:11:05

问题


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

(both on D: drive)

boost_regex compiled with:

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

code:

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

compiled with parameters:

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

It compiles ok, but I haven't yet tested if it will be working in more complex code. Removing the -Os switch clears the error but app size is 2x bigger then.

Maybe I should build Boost with size optimization too also but I don't know where to pass this option in b2 command line.


回答1:


In my case boost 1.58 was internally compiling with "-march=i686", but my code wasn't. Adding "-march=i686" to my project got rid of all "duplicate section".

lesson learned: always make painstakingly sure that all libraries and the main project are compiled with identical compiler options.




回答2:


I believe this is a compiler bug. The workaround in my case was to add -fno-tree-vectorize.




回答3:


I got the same error when I compile my code use gcc-4.9.1 in MinGW32 with a lib which use gcc-4.4.7 as the compiler. And I also used ccache to speed up,ccache is also a problem. Remove the cache in ~/.ccache/ and recompiled then I workaround this.



来源:https://stackoverflow.com/questions/14181351/i-got-duplicate-section-errors-when-compiling-boost-regex-with-size-optimizati

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!