#4614 closed Bugs (fixed)
Unable to statically link thread lib on mingw/win32
Reported by: | 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 , 12 years ago
comment:2 by , 12 years ago
Looks like :) But BOOST_THREAD_DYN_LINK/BOOST_ALL_DYN_LINK is not defined by me.
comment:3 by , 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 , 12 years ago
Problem is here: file /boost/thread/detail/config.hpp:40 (boost version 1.44)
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 , 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
follow-up: 7 comment:6 by , 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
comment:7 by , 12 years ago
Replying to koradlow@…: complete Link: https://svn.boost.org/trac/boost/ticket/4258
comment:8 by , 12 years ago
Cc: | added |
---|---|
Milestone: | To Be Determined → Boost-1.45.0 |
Severity: | Regression → Showstopper |
follow-up: 11 comment:9 by , 12 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Static linking seems to work fine now #4258 is fixed.
comment:10 by , 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.
follow-up: 14 comment:11 by , 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:13 by , 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.
comment:14 by , 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.
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?