Code::Blocks Forums

User forums => Using Code::Blocks => Topic started by: arihim on September 22, 2010, 02:33:07 pm

Title: Boost Static Linking
Post by: arihim on September 22, 2010, 02:33:07 pm
Using Boost 1.44 with the latest Mingw

Writing a simple thread program with boost which I can link just fine to the .dll . Tried running, it no problem.
I tried statically linking to the library. Changed the library to the static version. Defined #define BOOST_THREAD_USE_LIB .

So here is the problem: no errors are reported during the building process but the executable fails to build.

Here's the build log :

Linking console executable: bin\Debug\PassTheBit.exe
c:/program files/codeblocks/mingw/bin/../lib/gcc/mingw32/4.5.0/../../../libmingw32.a(tlssup.o):tlssup.c:(.tls+0x0): multiple definition of `_tls_used'
..\..\..\boost_1_44_0\stage\lib\libboost_thread-mgw45-mt-s-1_44.a(tss_pe.o):tss_pe.cpp:(.rdata$T+0x0): first defined here
c:/program files/codeblocks/mingw/bin/../lib/gcc/mingw32/4.5.0/../../../../mingw32/bin/ld.exe: warning: auto-importing has been activated without --enable-auto-import specified on the command line.
This should work unless it involves constant data structures referencing symbols from auto-imported DLLs.
collect2: ld returned 1 exit status
Info: resolving vtable for std::exception by linking to __imp___ZTVSt9exception (auto-import)
Info: resolving vtable for std::bad_alloc by linking to __imp___ZTVSt9bad_alloc (auto-import)
Info: resolving std::cout  by linking to __imp___ZSt4cout (auto-import)
Info: resolving std::cin  by linking to __imp___ZSt3cin (auto-import)
Info: resolving vtable for __cxxabiv1::__si_class_type_info by linking to __imp___ZTVN10__cxxabiv120__si_class_type_infoE (auto-import)
Info: resolving vtable for __cxxabiv1::__vmi_class_type_info by linking to __imp___ZTVN10__cxxabiv121__vmi_class_type_infoE (auto-import)
Info: resolving vtable for __cxxabiv1::__class_type_info by linking to __imp___ZTVN10__cxxabiv117__class_type_infoE (auto-import)
Info: resolving vtable for __cxxabiv1::__pointer_type_info by linking to __imp___ZTVN10__cxxabiv119__pointer_type_infoE (auto-import)
Info: resolving vtable for std::runtime_error by linking to __imp___ZTVSt13runtime_error (auto-import)
Info: resolving vtable for std::logic_error by linking to __imp___ZTVSt11logic_error (auto-import)
Info: resolving std::basic_string<char, std::char_traits<char>, std::allocator<char> >::_Rep::_S_empty_rep_storage by linking to __imp___ZNSs4_Rep20_S_empty_rep_storageE (auto-import)
Process terminated with status 1 (0 minutes, 0 seconds)
0 errors, 1 warnings

Any suggestions ?
Title: Re: Boost Static Linking
Post by: reckless on September 22, 2010, 10:49:24 pm
"multiple definition of `_tls_used'" i think thats the part failing as i seen something like that in another program i compiled against boost the fix is quite easy though.

add -Wl,--allow-multiple-definition to the linker flags in build options. note the l after -W is not a 1 but a lowercase L.
Title: Re: Boost Static Linking
Post by: arihim on September 23, 2010, 01:04:53 am
"multiple definition of `_tls_used'" i think thats the part failing as i seen something like that in another program i compiled against boost the fix is quite easy though.

add -Wl,--allow-multiple-definition to the linker flags in build options. note the l after -W is not a 1 but a lowercase L.

Ok that works. Thanks for that.
For anyone else the steps I followed are : Clicked on Build Options after right clicking on my project root, then went to Linker Settings, then other options and pasted "-Wl,--allow-multiple-definition" .

Can someone point me to a document with all the possible linker flags for mingw and descriptions about what they do?

I also found a bug report for this : https://svn.boost.org/trac/boost/ticket/4258 (https://svn.boost.org/trac/boost/ticket/4258)
Title: Re: Boost Static Linking
Post by: stahta01 on September 23, 2010, 01:29:31 am
For GCC

http://gcc.gnu.org/onlinedocs/gcc/Option-Summary.html (http://gcc.gnu.org/onlinedocs/gcc/Option-Summary.html)
http://gcc.gnu.org/onlinedocs/gcc/Link-Options.html (http://gcc.gnu.org/onlinedocs/gcc/Link-Options.html)

Some BinUtils Options
http://sourceware.org/binutils/docs-2.20/ld/Options.html (http://sourceware.org/binutils/docs-2.20/ld/Options.html)

Tim S.

Title: Re: Boost Static Linking
Post by: reckless on September 23, 2010, 11:27:07 am
np ;)

its actually a bit weird that this option even exists as multiple definitions are generally ok on a win32 target. not sure about linux though.