Boost's undefined references

Started by
19 comments, last by random_thinker 13 years, 5 months ago
@random_thinker
I can't find that option on my CB compiler settings, by latest do you mean the v10.05 or the latest nightly build? By the way I'm using the CB 10.05/MinGW package.

I tried the 1.43 and I end up having the #4258 issue.

I'll try using the latest MinGW now not the one from the Code::Block/MinGW package and see if I can make it work.
myWebSite : https://sites.google.com/site/vehement04/
Advertisement
It might not be associated with codeblocks, it could be the latest version of GCC. I'm not sure. The current versions I'm using are:

GCC: 4.4.4 20100630 (Red Hat 4.4.4-10)
Code::Blocks: 10.05

The above combination does not offer any multi-threaded compiler settings; ie no need to set them. My older system had an extensive list, and it was quite tricky to set up.

--random_thinkerAs Albert Einstein said: 'Imagination is more important than knowledge'. Of course, he also said: 'If I had only known, I would have been a locksmith'.
I've recompiled boost 1.44 with the MinGW from MinGW-Get and now I'm getting this error.
Compiling: main.cppIn file included from C:\Boost\include/boost/thread/win32/thread_data.hpp:12:0,                 from C:\Boost\include/boost/thread/thread.hpp:15,                 from C:\Codes\Test\main.cpp:1:C:\Boost\include/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 ignoredC:\Boost\include/boost/thread/win32/thread_heap_alloc.hpp:69:39: warning: inline function 'void boost::detail::free_raw_heap_memory(void*)' declared as  dllimport: attribute ignoredIn file included from C:\Boost\include/boost/thread/shared_mutex.hpp:14:0,                 from C:\Boost\include/boost/thread/detail/thread_group.hpp:9,                 from C:\Boost\include/boost/thread/thread.hpp:24,                 from C:\Codes\Test\main.cpp:1:C:\Boost\include/boost/thread/win32/shared_mutex.hpp: In member function 'T boost::shared_mutex::interlocked_compare_exchange(T*, T, T) [with T = boost::shared_mutex::state_data]':C:\Boost\include/boost/thread/win32/shared_mutex.hpp:110:103:   instantiated from hereC:\Boost\include/boost/thread/win32/shared_mutex.hpp:50:99: warning: dereferencing type-punned pointer will break strict-aliasing rulesC:\Boost\include/boost/thread/win32/shared_mutex.hpp:50:99: warning: dereferencing type-punned pointer will break strict-aliasing rulesC:\Boost\include/boost/thread/win32/shared_mutex.hpp:51:52: warning: dereferencing type-punned pointer will break strict-aliasing rulesC:\Boost\include/boost/thread/win32/shared_mutex.hpp:51:52: warning: dereferencing type-punned pointer will break strict-aliasing rulesLinking console executable: bin\Release\Test.exec:/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.obj\Release\main.o:main.cpp:(.text+0x176): undefined reference to `_imp___ZN5boost6thread12start_threadEv'obj\Release\main.o:main.cpp:(.text+0x1ef): undefined reference to `_imp___ZN5boost6thread4joinEv'obj\Release\main.o:main.cpp:(.text+0x1f8): undefined reference to `_imp___ZN5boost6threadD1Ev'obj\Release\main.o:main.cpp:(.text+0x620): undefined reference to `_imp___ZN5boost6threadD1Ev'collect2: ld returned 1 exit statusInfo: resolving vtable for std::bad_alloc by linking to __imp___ZTVSt9bad_alloc (auto-import)Info: resolving std::cout  by linking to __imp___ZSt4cout (auto-import)Info: resolving std::cin  by linking to __imp___ZSt3cin (auto-import)Info: resolving vtable for __cxxabiv1::__vmi_class_type_info by linking to __imp___ZTVN10__cxxabiv121__vmi_class_type_infoE (auto-import)Info: resolving vtable for __cxxabiv1::__class_type_info by linking to __imp___ZTVN10__cxxabiv117__class_type_infoE (auto-import)Info: resolving vtable for __cxxabiv1::__si_class_type_info by linking to __imp___ZTVN10__cxxabiv120__si_class_type_infoE (auto-import)Process terminated with status 1 (0 minutes, 1 seconds)4 errors, 7 warnings

I've read somewhere that adding BOOST_THREAD_USE_LIB in compiler options might help but I end up with another error.
Compiling: main.cppIn file included from C:\Boost\include/boost/thread/shared_mutex.hpp:14:0,                 from C:\Boost\include/boost/thread/detail/thread_group.hpp:9,                 from C:\Boost\include/boost/thread/thread.hpp:24,                 from C:\Codes\Test\main.cpp:1:C:\Boost\include/boost/thread/win32/shared_mutex.hpp: In member function 'T boost::shared_mutex::interlocked_compare_exchange(T*, T, T) [with T = boost::shared_mutex::state_data]':C:\Boost\include/boost/thread/win32/shared_mutex.hpp:110:103:   instantiated from hereC:\Boost\include/boost/thread/win32/shared_mutex.hpp:50:99: warning: dereferencing type-punned pointer will break strict-aliasing rulesC:\Boost\include/boost/thread/win32/shared_mutex.hpp:50:99: warning: dereferencing type-punned pointer will break strict-aliasing rulesC:\Boost\include/boost/thread/win32/shared_mutex.hpp:51:52: warning: dereferencing type-punned pointer will break strict-aliasing rulesC:\Boost\include/boost/thread/win32/shared_mutex.hpp:51:52: warning: dereferencing type-punned pointer will break strict-aliasing rulesLinking console executable: bin\Release\Test.exec:/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.obj\Release\main.o:main.cpp:(.text+0x175): undefined reference to `boost::thread::start_thread()'obj\Release\main.o:main.cpp:(.text+0x1ed): undefined reference to `boost::thread::join()'obj\Release\main.o:main.cpp:(.text+0x1f5): undefined reference to `boost::thread::~thread()'obj\Release\main.o:main.cpp:(.text+0x61b): undefined reference to `boost::thread::~thread()'collect2: ld returned 1 exit statusInfo: resolving vtable for std::bad_alloc by linking to __imp___ZTVSt9bad_alloc (auto-import)Info: resolving std::cout  by linking to __imp___ZSt4cout (auto-import)Info: resolving std::cin  by linking to __imp___ZSt3cin (auto-import)Info: resolving vtable for __cxxabiv1::__vmi_class_type_info by linking to __imp___ZTVN10__cxxabiv121__vmi_class_type_infoE (auto-import)Info: resolving vtable for __cxxabiv1::__class_type_info by linking to __imp___ZTVN10__cxxabiv117__class_type_infoE (auto-import)Info: resolving vtable for __cxxabiv1::__si_class_type_info by linking to __imp___ZTVN10__cxxabiv120__si_class_type_infoE (auto-import)Process terminated with status 1 (0 minutes, 1 seconds)4 errors, 5 warnings

By the way this is what I'm trying to compile.
#include <boost/thread.hpp>#include <iostream>#include <string>bool quit = false;void Test2( void ) {    while( !quit ) {        std::cout << "Running" << std::endl;    }}int main(){    boost::thread t( Test2 );    std::cout << "Thread" << std::endl;    char a;    std::cin >> a;    quit = true;    t.join();    return 0;}
myWebSite : https://sites.google.com/site/vehement04/
I don't see anything that is really wrong with your code.

Have you tried setting the compiler flag: --enable-auto-import as the warnings suggest?

Other suggestions: #include <windows.h> in main; exposes the windows threading api.

Some other possible header includes:

<stdafx.h>
<windows.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>

Pthread.h and pthreads for windows are only useful for certain versions. I don't think that Vista and 7 are included.

#include <Pthread.h> // optional, need ms pthreads library see below.

More information at http://technet.microsoft.com/en-us/library/bb463209.aspx concerning pthreads and windows. You can download windows services for Unix here: http://www.microsoft.com/downloads/en/details.aspx?FamilyID=896C9688-601B-44F1-81A4-02878FF11778&displaylang=en

This is an extreme fall back position:

In the extreme; have you tried the linker flag -lpthread or -pthread in code::blocks? You can get a pthreads-w32.dll at sourceware.org. (sourceware.org/pthreads-win32/).

[Edited by - random_thinker on November 4, 2010 9:51:03 AM]
--random_thinkerAs Albert Einstein said: 'Imagination is more important than knowledge'. Of course, he also said: 'If I had only known, I would have been a locksmith'.
@random_thinker
Yeah I tried adding the --enable-auto-import but I still get the warning warning about it.

I tried your suggestions about windows.h and pthreads but I still get the same error. Ugh, I'm out of ideas of how to make this work now. I guess I can't compile Ogre now.
myWebSite : https://sites.google.com/site/vehement04/
That's very strange.

I use Fedora for almost all my development work, but I have used Windows Vista for testing purposes, and I'm certain that boost::threads worked for me. I'll have a look at the set up...I'm assuming you are using Vista or 7?

Can you use C++0x? There is reportedly a native thread library built in. I haven't tried it yet. Instructional video is here:

">

--random_thinkerAs Albert Einstein said: 'Imagination is more important than knowledge'. Of course, he also said: 'If I had only known, I would have been a locksmith'.
I've archived both the bind, thread, and posix_time libraries in one static library under windows. The release boost archive was 395k which is much larger than just the threads library alone.

I'm pretty sure that bind is required, and date_time would be needed for the this_thread::sleep() function. Anyway, I've written a template library wrapper for these things with some typedefs to make life easier.

An example of the code for a sleeping boost thread follows using all three libraries:

#include <boost/bind.hpp>
#include <boost/thread.hpp>
#include <boost/date_time.hpp> // optional: hours(),minutes(),seconds() milliseconds()

int time;
boost::this_thread::sleep( boost::posix_time::minutes( time ) );

This **should** work on both Vista and Fedora.

For the Vista system, I'm using code::blocks, mingw, and gcc, but it's a much older version of gcc; MinGW 5.1.6 and GCC 3.4.5. That's old. Boost version looks like 1.40. That's old too.

I'm using boost 1.44 under Fedora with GCC 4.4.4.

--random_thinkerAs Albert Einstein said: 'Imagination is more important than knowledge'. Of course, he also said: 'If I had only known, I would have been a locksmith'.
I've been doing some testing of the mingw32 system under Fedora. This allows Windows apps to be compiled under Linux.

There is a mingw pthreads-w32 library, and this requires the linker switch -lpthread. I believe that the boost threads library requires this.

If you haven't had any joy yet you may want to install this library and use the linker switch. The library can be found at:

http://sourceforge.net/projects/mingw/files_beta/MinGW/pthreads-w32/
--random_thinkerAs Albert Einstein said: 'Imagination is more important than knowledge'. Of course, he also said: 'If I had only known, I would have been a locksmith'.
Thank you guys. I've got it working now.

I've run through the fixes you've suggested and from the boost tickets again and I've got it working now. I've applied the fixes on boost ticket #4164 with the define and the one from koradlow link.

I think I missed something while doing those fixes on my first try.
myWebSite : https://sites.google.com/site/vehement04/
Good news.

Funny I'm trying to set up the cross compile system in Fedora 12 x64 using wine, mingw32 + code::blocks.

Everything seems to work out of the box except boost::threads. Getting the error:

undefined reference to `boost::this_thread::interruptible_wait(void*,boost::detail::timeout)'
--random_thinkerAs Albert Einstein said: 'Imagination is more important than knowledge'. Of course, he also said: 'If I had only known, I would have been a locksmith'.

This topic is closed to new replies.

Advertisement