Opened 12 years ago

Closed 10 years ago

Last modified 9 years ago

#4878 closed Bugs (fixed)

MinGW 4.5.0 undefined reference to bool interruptible_wait(detail::win32::handle handle_to_wait_for,detail::t imeout target_time)

Reported by: 1czajnik@… Owned by: viboes
Milestone: Boost 1.54.0 Component: thread
Version: Boost 1.53.0 Severity: Problem
Keywords: Cc: admin@…, kevin.brightwell2@…

Description (last modified by viboes)

test.cpp:

#include <boost/thread.hpp>
int main()
{
	boost::this_thread::sleep( boost::get_system_time() + 
                boost::posix_time::milliseconds(50) );
}
g++ -lboost_thread-mt:
In file included from C:/boost/include/boost-1_45_0/boost/thread/win32/thread_data.hpp:12:0,
                 from C:/boost/include/boost-1_45_0/boost/thread/thread.hpp:15,
                 from C:/boost/include/boost-1_45_0/boost/thread.hpp:13,
                 from test.cpp:8:
C:/boost/include/boost-1_45_0/boost/thread/win32/thread_heap_alloc.hpp:59:40: warning: inline function 'void* boost::detail::allocate_raw_heap_memory(unsigned int)' declared as  dllimport: attribute ignored
C:/boost/include/boost-1_45_0/boost/thread/win32/thread_heap_alloc.hpp:69:39: warning: inline function 'void boost::detail::free_raw_heap_memory(void*)' declared as  dllimport: attribute ignored
c:/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.
C:\DOCUME~1\ADMINI~1\USTAWI~1\Temp\ccW8Zsal.o:test.cpp:(.text$_ZN5boost11this_thread18interruptible_waitERKNS_10posix_time5ptimeE[boost::this_thread::interruptible_wait(boost::posix_time::ptime const&)]+0x37): undefined reference to `_imp___ZN5boost11this_thread18interruptible_waitEPvNS_6detail7timeoutE'
collect2: ld returned 1 exit status

I have fixed this, but I do not know, if it is the right way: boost/thread/detail/config.hpp line 40:

#       if defined(BOOST_MSVC) || defined(BOOST_INTEL_WIN) || \
                ( __GNUC__ >= 4 && __GNUC_MINOR >= 5 )

This fix gets rid of the link error, and the earlier warning.

Cheers

Change History (16)

comment:1 by Hendricks266@…, 12 years ago

I'm getting the same error, with MinGW32 4.5.0 and Boost from trunk, but the change to boost/thread/detail/config.hpp did not fix the problem.

.cpp:(.text$_ZN5boost11this_thread18interruptible_waitEm[boost::this_thread::interruptible_wait(unsigned long)]+0x40):
undefined reference to `_imp___ZN5boost11this_thread18interruptible_waitEPvNS_6detail7timeoutE'
collect2: ld returned 1 exit status

comment:2 by Krzysztof Czaiński <1czajnik@…>, 12 years ago

I just looked at this line again, and I think I made a typo (missing underscores), boost/thread/detail/config.hpp line 40 is supposed to be:

#       if defined(BOOST_MSVC) || defined(BOOST_INTEL_WIN) \
                || ( __GNUC__ >= 4 && __GNUC_MINOR__ >= 5 ) // fix for mingw-4.5

Regards

comment:3 by Hendricks266 <Hendricks266@…>, 12 years ago

It works! Thank you.

comment:4 by Bryce Adelstein Lelbach, 12 years ago

Alright, I see why this fix is working (relevant code, aka $BOOST_ROOT/boost/thread/detail/config.hpp).

 34 #if defined(BOOST_THREAD_BUILD_DLL)   //Build dll                                
 35 #elif defined(BOOST_THREAD_BUILD_LIB) //Build lib                                
 36 #elif defined(BOOST_THREAD_USE_DLL)   //Use dll                                  
 37 #elif defined(BOOST_THREAD_USE_LIB)   //Use lib                                  
 38 #else //Use default                                                              
 39 #   if defined(BOOST_THREAD_PLATFORM_WIN32)                                      
 40 #       if defined(BOOST_MSVC) || defined(BOOST_INTEL_WIN)                       
 41             //For compilers supporting auto-tss cleanup                          
 42             //with Boost.Threads lib, use Boost.Threads lib                      
 43 #           define BOOST_THREAD_USE_LIB                                          
 44 #       else                                                                     
 45             //For compilers not yet supporting auto-tss cleanup                  
 46             //with Boost.Threads lib, use Boost.Threads dll                      
 47 #           define BOOST_THREAD_USE_DLL                                          
 48 #       endif                                                                    
 49 #   else                                                                         
 50 #       define BOOST_THREAD_USE_LIB                                              
 51 #   endif                                                                        
 52 #endif   

I would be happy to apply a patch for this (though, a more versatile patch: Hendricks seemed to indicate on IRC that this is not just a problem for mingw 4.5, but a problem for mingw in general, so any mingw version should be detected, if this is in fact the right fix), but first I need to see some justification for this solution. If someone is interested in doing a little more investigating, read on and post your findings here.

It seems that the Boost.Threads dll is not working with mingw. The comments from the above snippet seem to indicate that the Boost.Threads lib should be used for compilers supporting auto-tss cleanup. Does mingw support auto-tss cleanup? (cite sources, please).

More importantly, it looks like the underlying problem might be that BOOST_THREAD_PLATFORM_WIN32 appears to be defined for mingw. Why is this happening (please check the Boost.Thread / Boost.Config source code, and find out where BOOST_THREAD_PLATFORM_WIN32 is being defined)? Is it an error? If BOOST_THREAD_PLATFORM_WIN32 wasn't defined, it looks like BOOST_THREAD_USE_LIB would be selected. Would this fix the mingw problem?

Also, this needs to be tested - e.g. someone with this fix applied needs to run the Boost.Thread test suite on GCC Linux and mingw.

comment:5 by Bryce Adelstein Lelbach, 12 years ago

Cc: admin@… added

comment:6 by Hendricks266 <Hendricks266@…>, 12 years ago

It appears that this bug was "fixed" before: #4614

--Side Note--

In bug #4614, reference is made to this bug #4315. I got these warnings as well.

--End Side Note--

I can't find any information regarding auto-tss cleanup in MinGW or GCC. If tss is an acronym for "thread stack size", a web search of [auto thread stack size cleanup site:gnu.org] may be on the right track.

Here's the MinGW-encompassing modification:

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

Relevant link: http://redmine.webtoolkit.eu/projects/wt/wiki/Installing_Wt_on_MinGW

On the BOOST_THREAD_PLATFORM_WIN32 front, this is $BOOST_ROOT/boost/thread/detail/platform.hpp:

// fetch compiler and platform configuration
#include <boost/config.hpp>

// insist on threading support being available:
#include <boost/config/requires_threads.hpp>

// choose platform
#if defined(linux) || defined(__linux) || defined(__linux__)
#  define BOOST_THREAD_LINUX
#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)
#  define BOOST_THREAD_BSD
#elif defined(sun) || defined(__sun)
#  define BOOST_THREAD_SOLARIS
#elif defined(__sgi)
#  define BOOST_THREAD_IRIX
#elif defined(__hpux)
#  define BOOST_THREAD_HPUX
#elif defined(__CYGWIN__)
#  define BOOST_THREAD_CYGWIN
#elif (defined(_WIN32) || defined(__WIN32__) || defined(WIN32)) && !defined(BOOST_DISABLE_WIN32)
#  define BOOST_THREAD_WIN32
#elif defined(__BEOS__)
#  define BOOST_THREAD_BEOS
#elif defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__)
#  define BOOST_THREAD_MACOS
#elif defined(__IBMCPP__) || defined(_AIX)
#  define BOOST_THREAD_AIX
#elif defined(__amigaos__)
#  define BOOST_THREAD_AMIGAOS
#elif defined(__QNXNTO__)
#  define BOOST_THREAD_QNXNTO
#elif defined(unix) || defined(__unix) || defined(_XOPEN_SOURCE) || defined(_POSIX_SOURCE)
#       if defined(BOOST_HAS_PTHREADS) && !defined(BOOST_THREAD_POSIX)
#               define BOOST_THREAD_POSIX
#       endif
#endif

// For every supported platform add a new entry into the dispatch table below.
// BOOST_THREAD_POSIX is tested first, so on platforms where posix and native
// threading is available, the user may choose, by defining BOOST_THREAD_POSIX
// in her source. If a platform is known to support pthreads and no native
// port of boost_thread is available just specify "pthread" in the
// dispatcher table. If there is no entry for a platform but pthreads is
// available on the platform, pthread is choosen as default. If nothing is
// available the preprocessor will fail with a diagnostic message.
 
#if defined(BOOST_THREAD_POSIX)
#  define BOOST_THREAD_PLATFORM_PTHREAD
#else
#  if defined(BOOST_THREAD_WIN32)
#       define BOOST_THREAD_PLATFORM_WIN32
#  elif defined(BOOST_HAS_PTHREADS)
#       define BOOST_THREAD_PLATFORM_PTHREAD
#  else
#       error "Sorry, no boost threads are available for this platform."
#  endif
#endif

WIN32 appears to go all the way to the base of Boost.

I would be willing to run the Boost.Thread test suite on MinGW. How do I run it?

comment:7 by viboes, 11 years ago

Go to libs/thread/test and do

bjam toolset=<name as defined on your user-config.jam>

comment:8 by viboes, 10 years ago

Description: modified (diff)

comment:9 by viboes, 10 years ago

Could you show the failing command line? Have you tried adding --enable-auto-import to the command line as suggested by the error message?

comment:10 by viboes, 10 years ago

Resolution: worksforme
Status: newclosed

This is working for me. Please open it if you have problems on trunk (or 1.53).

comment:11 by Kevin Brightwell <kevin.brightwell2@…>, 10 years ago

I encountered this error using Boost 1.53.0 on MinGW 4.7 on Windows 7.

I applied the following at line 318 in boost\thread\detail\config.hpp

#if defined(BOOST_THREAD_BUILD_DLL)   //Build dll
#elif defined(BOOST_THREAD_BUILD_LIB) //Build lib
#elif defined(BOOST_THREAD_USE_DLL)   //Use dll
#elif defined(BOOST_THREAD_USE_LIB)   //Use lib
#else //Use default
#   if defined(BOOST_THREAD_PLATFORM_WIN32)
#       if defined(BOOST_MSVC) || defined(BOOST_INTEL_WIN) \
			|| defined(__MINGW32__) || defined(MINGW32) || defined(BOOST_MINGW32)
            //For compilers supporting auto-tss cleanup
            //with Boost.Threads lib, use Boost.Threads lib
#           define BOOST_THREAD_USE_LIB
#       else
            //For compilers not yet supporting auto-tss cleanup
            //with Boost.Threads lib, use Boost.Threads dll
#           define BOOST_THREAD_USE_DLL
#       endif
#   else
#       define BOOST_THREAD_USE_LIB
#   endif
#endif

This is the exact solution from: https://svn.boost.org/trac/boost/ticket/4878#comment:6

comment:12 by Kevin Brightwell <kevin.brightwell2@…>, 10 years ago

Cc: kevin.brightwell2@… added
Resolution: worksforme
Status: closedreopened
Version: Boost 1.45.0Boost 1.53.0

comment:13 by viboes, 10 years ago

Changeset [83796]

comment:14 by viboes, 10 years ago

Milestone: To Be DeterminedBoost 1.54.0
Owner: changed from Anthony Williams to viboes
Status: reopenednew

Merge from trunk [83811].

comment:15 by viboes, 10 years ago

Resolution: fixed
Status: newclosed

comment:16 by anonymous, 9 years ago

I also encountered this error while using Boost 1.53.0 on MinGW 4.7.2 on Windows 7. (on Jun 2013)

I applied the fix as listed by Kevin Brightwell at line 318 in boost\thread\detail\config.hpp

I thought this was fixed 3 months ago?

Note: See TracTickets for help on using tickets.