Author Topic: Boost Static Linking  (Read 13135 times)

Offline arihim

  • Single posting newcomer
  • *
  • Posts: 2
Boost Static Linking
« 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 ?

Offline reckless

  • Regular
  • ***
  • Posts: 338
Re: Boost Static Linking
« Reply #1 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.

Offline arihim

  • Single posting newcomer
  • *
  • Posts: 2
Re: Boost Static Linking
« Reply #2 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

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7582
    • My Best Post
« Last Edit: September 23, 2010, 01:44:07 am by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline reckless

  • Regular
  • ***
  • Posts: 338
Re: Boost Static Linking
« Reply #4 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.