[boost.thread] Trouble building with MinGw 4.7.0

Hi all, Up until now I have been developing exclusively with VC++ 2010, and there my project builds just fine and without warnings. However, I am also planning to target Unix so I figured that a first step would be to make sure my project builds with MinGw. I set up my path environment variable to include the location of the MinGw 4.7.0 bin directory, and I built Boost with the following parameters: b2 variant=release link=static runtime-link=static threading=multi toolset=gcc Everything seems to be working fine (stage/lib contains all the .a files that I would expect). However, when I attempt to build my program I get tons of errors like the following: myprog_main.o:myprog_main.cpp:(.text+0x28ef): undefined reference to `__imp___ZN5boost6thread9interruptEv' myprog_main.o:myprog_main.cpp:(.text+0x294f): undefined reference to `__imp___ZNK5boost6thread6get_idEv' myprog_main.o:myprog_main.cpp:(.text+0x295d): undefined reference to `__imp___ZN5boost11this_thread6get_idEv' myprog_main.o:myprog_main.cpp:(.text+0x2973): undefined reference to `__imp___ZN5boost6thread13join_noexceptEv' myprog_main.o:myprog_main.cpp:(.text+0x2981): undefined reference to `__imp___ZN5boost6thread6detachEv' myprog_main.o:myprog_main.cpp:(.text+0x4600): undefined reference to `__imp___ZN5boost11this_thread18interruptible_waitEPvNS_6detail7timeoutE' myprog_main.o:myprog_main.cpp:(.text+0x49c2): undefined reference to `__imp___ZN5boost11this_thread18interruptible_waitEPvNS_6detail7timeoutE' myprog_main.o:myprog_main.cpp:(.text+0x667e): undefined reference to `__imp___ZN5boost11this_thread18interruptible_waitEPvNS_6detail7timeoutE' myprog_main.o:myprog_main.cpp:(.text+0x90a9): undefined reference to `__imp___ZN5boost6thread21start_thread_noexceptEv' myprog_main.o:myprog_main.cpp:(.text+0x9134): undefined reference to `__imp___ZN5boost6thread21start_thread_noexceptEv' myprog_main.o:myprog_main.cpp:(.text+0x917e): undefined reference to `__imp___ZN5boost6thread9interruptEv' myprog_main.o:myprog_main.cpp:(.text$_ZN5boost6detail11thread_dataINS_3_bi6bind_tIvPFvPN5myprog5themeEENS2_5list1INS2_5valueIS6_EEEEEEED1Ev[boost::detail::thread_data<boost::_bi::bind_t<void, void (*)(myprog::theme*), boost::_bi::list1<boost::_bi::value<myprog::theme*> > >
::~thread_data()]+0x7): undefined reference to `__imp___ZN5boost6detail16thread_data_baseD2Ev' myprog_main.o:myprog_main.cpp:(.text$_ZN5boost6detail11thread_dataINS_3_bi6bind_tIvPFvPN5myprog5themeEENS2_5list1INS2_5valueIS6_EEEEEEED0Ev[boost::detail::thread_data<boost::_bi::bind_t<void, void (*)(myprog::theme*), boost::_bi::list1<boost::_bi::value<myprog::theme*> > > ::~thread_data()]+0xe): undefined reference to `__imp___ZN5boost6detail16thread_data_baseD2Ev' myprog_main.o:myprog_main.cpp:(.text$_ZN5boost6threadD1Ev[boost::thread::~thread()]+0x9): undefined reference to `__imp___ZN5boost6thread6detachEv'
Etc... I tried to specify -DBOOST_NO_LIB and add all the libraries manually, but no luck. Then I thought that maybe there's a problem with the fact that there are spaces in some of my directory names, so I copied the relevant .a files to the same directory as the program itself but still with no success. At this point, I'm swamped. I have managed to compile MinGw programs in the past that used Boost Thread, so I have no idea why it is not working with this version of Boost. Any suggestions would be highly appreciated. Kind regards, Philip Bennefall

On Thu, Aug 1, 2013 at 3:15 PM, Philip Bennefall <philip@blastbay.com> wrote:
Hi all,
Up until now I have been developing exclusively with VC++ 2010, and there my project builds just fine and without warnings. However, I am also planning to target Unix so I figured that a first step would be to make sure my project builds with MinGw. I set up my path environment variable to include the location of the MinGw 4.7.0 bin directory, and I built Boost with the following parameters:
b2 variant=release link=static runtime-link=static threading=multi toolset=gcc
Everything seems to be working fine (stage/lib contains all the .a files that I would expect). However, when I attempt to build my program I get tons of errors like the following:
myprog_main.o:myprog_main.cpp:(.text+0x28ef): undefined reference to `__imp___ZN5boost6thread9interruptEv' myprog_main.o:myprog_main.cpp:(.text+0x294f): undefined reference to `__imp___ZNK5boost6thread6get_idEv' myprog_main.o:myprog_main.cpp:(.text+0x295d): undefined reference to `__imp___ZN5boost11this_thread6get_idEv' myprog_main.o:myprog_main.cpp:(.text+0x2973): undefined reference to `__imp___ZN5boost6thread13join_noexceptEv' myprog_main.o:myprog_main.cpp:(.text+0x2981): undefined reference to `__imp___ZN5boost6thread6detachEv' myprog_main.o:myprog_main.cpp:(.text+0x4600): undefined reference to `__imp___ZN5boost11this_thread18interruptible_waitEPvNS_6detail7timeoutE' myprog_main.o:myprog_main.cpp:(.text+0x49c2): undefined reference to `__imp___ZN5boost11this_thread18interruptible_waitEPvNS_6detail7timeoutE' myprog_main.o:myprog_main.cpp:(.text+0x667e): undefined reference to `__imp___ZN5boost11this_thread18interruptible_waitEPvNS_6detail7timeoutE' myprog_main.o:myprog_main.cpp:(.text+0x90a9): undefined reference to `__imp___ZN5boost6thread21start_thread_noexceptEv' myprog_main.o:myprog_main.cpp:(.text+0x9134): undefined reference to `__imp___ZN5boost6thread21start_thread_noexceptEv' myprog_main.o:myprog_main.cpp:(.text+0x917e): undefined reference to `__imp___ZN5boost6thread9interruptEv'
myprog_main.o:myprog_main.cpp:(.text$_ZN5boost6detail11thread_dataINS_3_bi6bind_tIvPFvPN5myprog5themeEENS2_5list1INS2_5valueIS6_EEEEEEED1Ev[boost::detail::thread_data<boost::_bi::bind_t<void, void (*)(myprog::theme*), boost::_bi::list1<boost::_bi::value<myprog::theme*> > >
::~thread_data()]+0x7): undefined reference to `__imp___ZN5boost6detail16thread_data_baseD2Ev' myprog_main.o:myprog_main.cpp:(.text$_ZN5boost6detail11thread_dataINS_3_bi6bind_tIvPFvPN5myprog5themeEENS2_5list1INS2_5valueIS6_EEEEEEED0Ev[boost::detail::thread_data<boost::_bi::bind_t<void, void (*)(myprog::theme*), boost::_bi::list1<boost::_bi::value<myprog::theme*> > > ::~thread_data()]+0xe): undefined reference to `__imp___ZN5boost6detail16thread_data_baseD2Ev' myprog_main.o:myprog_main.cpp:(.text$_ZN5boost6threadD1Ev[boost::thread::~thread()]+0x9): undefined reference to `__imp___ZN5boost6thread6detachEv'
Etc...
I tried to specify -DBOOST_NO_LIB and add all the libraries manually, but no luck. Then I thought that maybe there's a problem with the fact that there are spaces in some of my directory names, so I copied the relevant .a files to the same directory as the program itself but still with no success. At this point, I'm swamped. I have managed to compile MinGw programs in the past that used Boost Thread, so I have no idea why it is not working with this version of Boost. Any suggestions would be highly appreciated.
Your program tries to link with Boost dynamically and you only built static libraries. The errors you listed only refer to Boost.Thread symbols, so I can't tell whether the problem is limited to Boost.Thread or to other Boost libraries as well. Make sure you didn't define BOOST_THREAD_DYN_LINK or BOOST_ALL_DYN_LINK when building your application.

Hi Andrey, I am positive that I am not defining either of those macros in my project. Also, since I specified -DBOOST_NO_LIB and linked explicitly with the static libraries, shouldn't that tell MinGw that I don't want the dynamic libraries? All problematic symbols seem to be related to boost.thread. I don't see any mention of boost system, chrono, datetime etc. Kind regards, Philip Bennefall

On Thu, Aug 1, 2013 at 3:39 PM, Philip Bennefall <philip@blastbay.com> wrote:
Hi Andrey,
I am positive that I am not defining either of those macros in my project. Also, since I specified -DBOOST_NO_LIB and linked explicitly with the static libraries, shouldn't that tell MinGw that I don't want the dynamic libraries?
Defining BOOST_ALL_NO_LIB (note that BOOST_NO_LIB is not correct) only affects auto-linking. It does not affect symbol name mangling, which differs for static libs and dlls.
All problematic symbols seem to be related to boost.thread. I don't see any mention of boost system, chrono, datetime etc.
I'd say there's some problem with Boost.Thread then. Could you try defining BOOST_THREAD_USE_LIB when building your application? Also, what is your Boost version?

Hi Andrey, BOOST_THREAD_USE_LIB got rid of all the linker errors for thread. Then, similar ones regarding system came up, so I defined BOOST_SYSTEM_USE_LIB and now everything builds like a charm. Thank you for your help! Kind regards, Philip Bennefall

I forgot to answer your question. My version is boost_1_53_0. Kind regards, Philip Bennefall
participants (2)
-
Andrey Semashev
-
Philip Bennefall