Modify

Ticket #4614 (closed Bugs: fixed)

Opened 4 years ago

Last modified 2 years ago

Unable to statically link thread lib on mingw/win32

Reported by: Danil Ilinykh <woodroof@…> Owned by: anthonyw
Milestone: Boost 1.45.0 Component: thread
Version: Boost 1.44.0 Severity: Showstopper
Keywords: Cc: wash

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

Attachments

Change History

comment:1 Changed 4 years ago by steven_watanabe

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 Changed 4 years ago by anonymous

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

comment:3 Changed 4 years ago by Danil Ilinykh <woodroof@…>

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

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

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 Changed 4 years ago by koradlow@…

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 follow-up: ↓ 7 Changed 4 years ago by koradlow@…

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 in reply to: ↑ 6 Changed 4 years ago by koradlow@…

comment:8 Changed 4 years ago by wash

  • Cc wash added
  • Severity changed from Regression to Showstopper
  • Milestone changed from To Be Determined to Boost-1.45.0

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

comment:9 follow-up: ↓ 11 Changed 4 years ago by anthonyw

  • Status changed from new to closed
  • Resolution set to fixed

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

comment:10 Changed 3 years ago by gtoknu

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

comment:11 in reply to: ↑ 9 ; follow-up: ↓ 14 Changed 3 years ago by WFrane

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 follow-up: ↓ 13 Changed 2 years ago by anonymous

Still don't work for me any suggestions?

comment:13 in reply to: ↑ 12 Changed 2 years ago by Karin J

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 in reply to: ↑ 11 Changed 2 years ago by poiuz

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.

View

Add a comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
The resolution will be deleted. Next status will be 'reopened'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.