Skip to main content
GameDev.net gamedev.net
🔒 Locked

Boost's undefined references

Started by GlaiveVehem Nov 2, 2010 at 9:43 AM 19 replies 17.6k views
Original Post
GlaiveVehem
GlaiveVehem
I'm having problem on using boost. Every time I use boost::thread I always get undefined reference to every class I use( even functions ). I've already linked to libboost_thread-mgw44-mt-1_44.a. I've compiled boost thread using
bjam --toolset=gcc stage --with-thread
I'm pretty sure the compiled libs from bjam is already usable for linkage or did I miss something to do?
myWebSite : https://sites.google.com/site/vehement04/
GlaiveVehem
GlaiveVehem
Here's the error.
obj\Release\main.o:main.cpp|| undefined reference to `_imp___ZN5boost6thread12start_threadEv'|obj\Release\main.o:main.cpp|| undefined reference to `_imp___ZN5boost6thread4joinEv'|obj\Release\main.o:main.cpp|| undefined reference to `_imp___ZN5boost6threadD1Ev'|obj\Release\main.o:main.cpp|| undefined reference to `_imp___ZN5boost6threadD1Ev'|||=== Build finished: 4 errors, 0 warnings ===|


I don't really know what I'm doing wrong here. Oh and the size of the thread lib is 579KB for the debug and 140KB for the release. Is that the size I'm supposed to get?
myWebSite : https://sites.google.com/site/vehement04/
GlaiveVehem
GlaiveVehem
I tried using the regex of boost and it compiles perfectly, no errors. Anyone, please help me on this. Because I need boost::thread for building ogre3d.
myWebSite : https://sites.google.com/site/vehement04/
Ohforf sake
Ohforf sake
Not sure if this is important, but the error messages look like Microsoft's compiler where as "--toolset=gcc" and "libboost_thread-mgw44-mt-1_44.a" indicate a build for GCC/mingw.
I'm not sure if MS's compiler can read .a libs with the name mangling and all beeing different.

Is there a way to build boost specifically for Visual Studio?
GlaiveVehem
GlaiveVehem
Quote:
Original post by Ohforf sake
Not sure if this is important, but the error messages look like Microsoft's compiler where as "--toolset=gcc" and "libboost_thread-mgw44-mt-1_44.a" indicate a build for GCC/mingw.
I'm not sure if MS's compiler can read .a libs with the name mangling and all beeing different.

Is there a way to build boost specifically for Visual Studio?

Thanks for the reply. I think there is a way but I'm using mingw32 4.4 not VC++. I've been on google for this past hours(right after I woke up) just to find some clues as to why the boost::thread yields undifined references while other boost libs works perfectly fine, unfortunately still no luck finding those.
myWebSite : https://sites.google.com/site/vehement04/
MaulingMonkey
MaulingMonkey
Are you actually linking against libboost libboost-thread?

I know there's autolinking mechanics if you're using MSVC. Dunno about MinGW — I avoid it entirely since MSVC is free and generally better.

A quick google also indicates you may be running afoul of a known issue (#4258, #4614), which you may be able to deal with by downgrading to boost 1.43 or waiting for 1.45 to come out.

[Edited by - MaulingMonkey on November 3, 2010 6:45:37 PM]
random_thinker
random_thinker
Sometimes these problems are a result of your compiler settings. What's your development platform and settings; are you linking to the correct library?

I'm using exactly the same library under Fedora, have you included the linker option '-lpthread' ? Size on Fedora IA64 is 191.5 (release).
--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'.
GlaiveVehem
GlaiveVehem
Quote:
Original post by MaulingMonkey
Are you actually linking against libboost libboost-thread?

I know there's autolinking mechanics if you're using MSVC. Dunno about MinGW — I avoid it entirely since MSVC is free and generally better.

A quick google also indicates you may be running afoul of a known issue (#4258, #4614), which you may be able to deal with by downgrading to boost 1.43 or waiting for 1.45 to come out.

Yeah I'm sure I'm linking it correctly. I even tried linking with an absolute path but it still gives me that error. I also compile executable on Linux, so I'm using Code::Block. With Code::Block I just need to copy and paste but on MSVC I think I'm going to port/import it to Code::Block projects. I don't know if importing projects on Code::Blocks also import the settings from MSVC but just to be sure I'm using CB.

Okay I'll try 1.43.
myWebSite : https://sites.google.com/site/vehement04/
random_thinker
random_thinker
Have you enabled multi-threaded compiler switches?

I'm also using codeblocks. I had the same problems within Fedora until I installed libboost_thread-gcc44-mt-1_44.a in my development directory, enabled multithreaded compiler settings (in the older codeblocks, or perhaps the previous version of GCC, latest one doesn't need this), installed the library link directory in the build options and set the linker option -lpthread (this might be linux-specific though).

[Edited by - random_thinker on November 4, 2010 4:21:02 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'.
GlaiveVehem
GlaiveVehem
@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/
random_thinker
random_thinker
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'.
GlaiveVehem
GlaiveVehem
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/
random_thinker
random_thinker
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 in main; exposes the windows threading api.

Some other possible header includes:



#include
#include
#include

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

#include // 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'.
GlaiveVehem
GlaiveVehem
@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/
random_thinker
random_thinker
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'.
random_thinker
random_thinker
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
#include
#include // 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'.
random_thinker
random_thinker
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'.
GlaiveVehem
GlaiveVehem
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/
random_thinker
random_thinker
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'.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.