Opened 12 years ago

Closed 12 years ago

Last modified 11 years ago

#4614 closed Bugs (fixed)

Unable to statically link thread lib on mingw/win32

Reported by: Danil Ilinykh <woodroof@…> Owned by: Anthony Williams
Milestone: Boost 1.45.0 Component: thread
Version: Boost 1.44.0 Severity: Showstopper
Keywords: Cc: Bryce Adelstein Lelbach

Description

Errors:
../Obj/win32-gcc/Debug/StatTester/StressTester.o:C:\Danil\Src\update\StressTester/Impl/StressTester.cpp:94: undefined reference to `_imp___ZN5boost6thread4joinEv'
../Obj/win32-gcc/Debug/StatTester/StressTester.o: In function `thread<boost::_bi::bind_t<unsigned int, boost::_mfi::mf0<unsigned int, boost::asio::io_service>, boost::_bi::list1<boost::_bi::value<boost::asio::io_service*> > > >':
C:\Danil\Src\update\StressTester/../../boost/mingw/boost/boost/thread/detail/thread.hpp:204: undefined reference to `_imp___ZN5boost6thread12start_threadEv'
../Obj/win32-gcc/Debug/StatTester/StressTester.o:C:\Danil\Src\update\StressTester/../../boost/mingw/boost/boost/checked_delete.hpp:34: undefined reference to `_imp___ZN5boost6threadD1Ev'

Works fine with boost 1.43

Change History (14)

comment:1 by Steven Watanabe, 12 years ago

From the error message, it looks like you compiled to link to dll. Is either BOOST_THREAD_DYN_LINK or BOOST_ALL_DYN_LINK defined?

comment:2 by anonymous, 12 years ago

Looks like :) But BOOST_THREAD_DYN_LINK/BOOST_ALL_DYN_LINK is not defined by me.

comment:3 by Danil Ilinykh <woodroof@…>, 12 years ago

If I try dynamic linking, it links well, but I get error while executing application: The application failed to initialize properly (0xc0000005)

comment:4 by Danil Ilinykh <woodroof@…>, 12 years ago

Problem is here: file /boost/thread/detail/config.hpp:40 (boost version 1.44)

I added "
defined(MINGW32)" at the end of line and all works fine (with exception if bug 4258, walkaround writed here: https://svn.boost.org/trac/boost/ticket/4258#comment:6)

comment:5 by koradlow@…, 12 years ago

I recompiled the lib with the proposed changes to config.hpp:40

if defined(BOOST_MSVC) || defined(BOOST_INTEL_WIN) || defined(MINGW32) || defined(BOOST_MINGW32)

But I still get the same linker error as mentioned above trying to link statically. Using boost 1.44, mingw 3.15 and gcc 4.4.0, dynamically linking works fine though

This is my link command which causes the errors

g++.exe  -static -o .../main.o -L/D/boost_1_44_0/stage/lib /D/boost_1_44_0/stage/lib/libboost_thread-mgw44-mt-sd-1_44.a 

btw: I also had to apply this patch https://svn.boost.org/trac/boost/ticket/4315

comment:6 by koradlow@…, 12 years ago

Found a solution that works for me: apply this patch: https://svn.boost.org/trac/boost/ticket/ recompile, add the preprocessor directive: BOOST_THREAD_USE_LIB
Now I can link against the static librarary without any problems

in reply to:  6 comment:7 by koradlow@…, 12 years ago

comment:8 by Bryce Adelstein Lelbach, 12 years ago

Cc: Bryce Adelstein Lelbach added
Milestone: To Be DeterminedBoost-1.45.0
Severity: RegressionShowstopper

Not a duplicate of #4258, I believe, though the fix given in #4258 apparently works for this.

comment:9 by Anthony Williams, 12 years ago

Resolution: fixed
Status: newclosed

Static linking seems to work fine now #4258 is fixed.

comment:10 by gtoknu, 12 years ago

nor koradlow answer, nor Danil answer worked for me, any hints? I can't figure it out why I can't link it.

in reply to:  9 ; comment:11 by WFrane, 12 years ago

Replying to anthonyw:

Static linking seems to work fine now #4258 is fixed.

It appears that adding #define BOOST_THREAD_USE_LIB before other boost thread-related preprocessor directives is still required for static linking when using MinGW (tested using Boost 1.45.0 and MinGW 4.4.1).

@gtoknu: This may be too late for you, but adding #define BOOST_THREAD_USE_LIB before the include statements for the boost headers worked for me. I also recompiled the boost libraries after modifying config.hpp in the manner indicated by koradlow in comment 5, but I'm not certain that doing so is necessary.

comment:12 by anonymous, 11 years ago

Still don't work for me any suggestions?

in reply to:  12 comment:13 by Karin J, 11 years ago

Replying to anonymous:

Still don't work for me any suggestions?

Try changing the order of the libraries. Some linkers take order into account. I am using Eclipse and it appears that the order that works is exactly opposite to what I assumed; namely, library A depending on library B is listed BEFORE B.

in reply to:  11 comment:14 by poiuz, 11 years ago

Replying to WFrane:

It appears that adding #define BOOST_THREAD_USE_LIB before other boost thread-related preprocessor directives is still required for static linking when using MinGW (tested using Boost 1.45.0 and MinGW 4.4.1).

It is still necessary with Boost 1.48 and MinGW GCC 4.6.2. Without #define BOOST_THREAD_USE_LIB the example Timer5 from the Boost.Asio tutorial cannot be linked to the static thread library.

Note: See TracTickets for help on using tickets.