11

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.

rsk82
  • 28,217
  • 50
  • 150
  • 240
  • 1
    [This unanswered question](http://stackoverflow.com/questions/11635485/regex-boost-library-linking-in-release-mode-warns-duplicate-section-has-differe) has the same problem. One of the comments suggests that the problem may be isolated to mingw-w64. Mingw-build's g++ 4.8.0 also presents this problem and fedora 17's g++ 4.7.2 does not, so he/she may be right. –  Jan 06 '13 at 12:14
  • 1
    As you said using size optimization (adding `optimization=space` to your boost build command) seems to remove the problem. You should put that as an answer if you can confirm that it works. PS: Well, the problem is now reversed, the compiler spews those errors/warnings whenever you don't use `-Os`. –  Jan 06 '13 at 12:16
  • @llonesmiz : thanks! this works. The problem was that I could not find this option, it is not printed by `b2 --help` nor `--help-options`. – rsk82 Jan 06 '13 at 12:27
  • 1
    If you plan to use only g++ (or compilers that accept the same command line flags) you could also use `cxxflags=-Os`. There is also `linkflags` to pass options to the linker. –  Jan 06 '13 at 13:26
  • 2
    I have the same problem with Crypto++. Both with MinGW and MinGW-w64. – Nikolai Sep 09 '13 at 16:55
  • See https://sourceforge.net/p/mingw/bugs/2042/ and https://sourceforge.net/p/mingw-w64/bugs/345/ – Nikolai Sep 14 '13 at 00:26
  • @Nikolai "-march=i686" worked for crypto++ with mingw. – Behrouz.M Sep 20 '15 at 11:42

3 Answers3

15

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.

user4808204
  • 151
  • 1
  • 3
3

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

Lorenzo Pistone
  • 5,028
  • 3
  • 34
  • 65
0

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.

Keven
  • 71
  • 1