[Boost-users] boost:thread compiling problem

114 views
Skip to first unread message

Shaolin

unread,
Aug 20, 2009, 7:55:51 PM8/20/09
to boost...@lists.boost.org
Hi Guys

I am try to create a thread with boost but eveytime I execute I get some freaky error messages. See code below followed by error msg:

#include <boost/thread/thread.hpp>
#include <iostream>
using namespace std;

void hello()
{
    cout << "hello" << endl;
}

int main(int argc, char* argv[])
{   
    boost::thread thrd1(&hello); // ERROR caused by the &hello param
    thrd1.join();
       
}


Error Message:

/tmp/cc3ymRwv.o: In function `main':
main.cc:(.text+0x417): undefined reference to `boost::thread::join()'
main.cc:(.text+0x422): undefined reference to `boost::thread::~thread()'
main.cc:(.text+0x43b): undefined reference to `boost::thread::~thread()'
/tmp/cc3ymRwv.o: In function `boost::mutex::mutex()':
main.cc:(.text._ZN5boost5mutexC1Ev[boost::mutex::mutex()]+0x45): undefined reference to `boost::thread_resource_error::thread_resource_error()'
main.cc:(.text._ZN5boost5mutexC1Ev[boost::mutex::mutex()]+0x4d): undefined reference to `boost::thread_resource_error::~thread_resource_error()'
main.cc:(.text._ZN5boost5mutexC1Ev[boost::mutex::mutex()]+0x55): undefined reference to `typeinfo for boost::thread_resource_error'
/tmp/cc3ymRwv.o: In function `boost::detail::thread_data<void (*)()>::~thread_data()':
main.cc:(.text._ZN5boost6detail11thread_dataIPFvvEED0Ev[boost::detail::thread_data<void (*)()>::~thread_data()]+0x16): undefined reference to `boost::detail::thread_data_base::~thread_data_base()'
/tmp/cc3ymRwv.o: In function `boost::detail::thread_data<void (*)()>::~thread_data()':
main.cc:(.text._ZN5boost6detail11thread_dataIPFvvEED1Ev[boost::detail::thread_data<void (*)()>::~thread_data()]+0x16): undefined reference to `boost::detail::thread_data_base::~thread_data_base()'
/tmp/cc3ymRwv.o: In function `boost::condition_variable::condition_variable()':
main.cc:(.text._ZN5boost18condition_variableC1Ev[boost::condition_variable::condition_variable()]+0x3a): undefined reference to `boost::thread_resource_error::thread_resource_error()'
main.cc:(.text._ZN5boost18condition_variableC1Ev[boost::condition_variable::condition_variable()]+0x42): undefined reference to `boost::thread_resource_error::~thread_resource_error()'
main.cc:(.text._ZN5boost18condition_variableC1Ev[boost::condition_variable::condition_variable()]+0x4a): undefined reference to `typeinfo for boost::thread_resource_error'
/tmp/cc3ymRwv.o: In function `boost::detail::thread_data_base::thread_data_base()':
main.cc:(.text._ZN5boost6detail16thread_data_baseC2Ev[boost::detail::thread_data_base::thread_data_base()]+0x1b): undefined reference to `vtable for boost::detail::thread_data_base'
/tmp/cc3ymRwv.o: In function `boost::thread::thread<void (*)()>(void (*)(), boost::disable_if<boost::is_convertible<void (*&)(), boost::detail::thread_move_t<void (*)()> >, boost::thread::dummy*>::type)':
main.cc:(.text._ZN5boost6threadC1IPFvvEEET_NS_10disable_ifINS_14is_convertibleIRS4_NS_6detail13thread_move_tIS4_EEEEPNS0_5dummyEE4typeE[boost::thread::thread<void (*)()>(void (*)(), boost::disable_if<boost::is_convertible<void (*&)(), boost::detail::thread_move_t<void (*)()> >, boost::thread::dummy*>::type)]+0x32): undefined reference to `boost::thread::start_thread()'
/tmp/cc3ymRwv.o:(.rodata._ZTIN5boost6detail11thread_dataIPFvvEEE[typeinfo for boost::detail::thread_data<void (*)()>]+0x8): undefined reference to `typeinfo for boost::detail::thread_data_base'
collect2: ld returned 1 exit status

Steven Watanabe

unread,
Aug 20, 2009, 8:08:31 PM8/20/09
to boost...@lists.boost.org
AMDG

Shaolin wrote:
> I am try to create a thread with boost but eveytime I execute I get some
> freaky error messages. See code below followed by error msg:
>
> #include <boost/thread/thread.hpp>
> #include <iostream>
> using namespace std;
>
> void hello()
> {
> cout << "hello" << endl;
> }
>
> int main(int argc, char* argv[])
> {
> boost::thread thrd1(&hello); // ERROR caused by the &hello param
> thrd1.join();
>
> }
>

You need to link to the thread library.
Please read the getting started guide.

In Christ,
Steven Watanabe

_______________________________________________
Boost-users mailing list
Boost...@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users

Shaolin

unread,
Aug 20, 2009, 8:47:09 PM8/20/09
to boost...@lists.boost.org
I have read the getting started section and its confused me even more.


2009/8/21 Steven Watanabe <watan...@gmail.com>

James C. Sutherland

unread,
Aug 20, 2009, 9:33:35 PM8/20/09
to boost...@lists.boost.org
On Aug 20, 2009, at 6:47 PM, Shaolin wrote:

I have read the getting started section and its confused me even more.

Read it again ;-)

boost::thread is a compiled library that you must link against.  Be sure that you have compiled and installed the library, and that you are including the appropriate link command.

Shaolin

unread,
Aug 21, 2009, 12:03:05 PM8/21/09
to boost...@lists.boost.org
Ok, I have managed to compile and install the libs but I dont know how to include it in the commandline. The regex example works fine but how do I do it for thread ?

$ c++ -I path/to/boost_1_39_0 example.cpp -o example \
~/boost/stage/lib/libboost_regex-gcc34-mt-d-1_36.a



2009/8/21 James C. Sutherland <James.Su...@utah.edu>

Rush Manbert

unread,
Aug 21, 2009, 12:35:21 PM8/21/09
to boost...@lists.boost.org
On Aug 21, 2009, at 9:03 AM, Shaolin wrote:

Ok, I have managed to compile and install the libs but I dont know how to include it in the commandline. The regex example works fine but how do I do it for thread ?

$ c++ -I path/to/boost_1_39_0 example.cpp -o example \
~/boost/stage/lib/libboost_regex-gcc34-mt-d-1_36.a



The library naming all follows a pattern, so:

 ~/boost/stage/lib/libboost_thread-gcc34-mt-d-1_36.a

which should work if you actually built the library.

- Rush

Shaolin

unread,
Aug 21, 2009, 1:46:42 PM8/21/09
to boost...@lists.boost.org
Thanks, it looks like I didnt install it properly .. below is the error message I get:

g++:  ~/boost/stage/lib/libboost_thread-gcc34-mt-d-1_36.a: No such file or directory

This is what I did the install the lib.
$ cd /usr/local/boost_1_39_0
$ sudo ./bootstrap.sh
$ sudo ./bjam install



2009/8/21 Rush Manbert <ru...@manbert.com>

Roman Shmelev

unread,
Aug 21, 2009, 2:39:30 PM8/21/09
to boost...@lists.boost.org
I do not know if I will be able to help, but I use simple:
-lboost_thread
*there is L letter before boost_thread*

Steven Watanabe

unread,
Aug 21, 2009, 2:47:48 PM8/21/09
to boost...@lists.boost.org
AMDG

Shaolin wrote:
> Thanks, it looks like I didnt install it properly .. below is the error
> message I get:
>

> *g++: ~/boost/stage/lib/libboost_thread-gcc34-mt-d-1_36.a: No such file or
> directory*


>
> This is what I did the install the lib.
> $ cd /usr/local/boost_1_39_0
> $ sudo ./bootstrap.sh
> $ sudo ./bjam install
>

bjam install places the libraries under /usr/lib
bjam stage or just bjam puts the libraries
in stage/lib.

In Christ,
Steven Watanabe

Shaolin

unread,
Aug 21, 2009, 3:43:13 PM8/21/09
to boost...@lists.boost.org
Ok, I have reconfigured it and the file is now located in the boost_1_39_0 directory. However, it still doesnt work. This is what I type in command line:

g++ -I /usr/local/boost_1_39_0 test.cc -o example \ ~/stage/lib/libboost_thread-gcc43-mt-1_39.a

stage directory: /usr/local/boost_1_39_0/stage/lib/libboost_thread-gcc43-mt-1_39.a



2009/8/21 Steven Watanabe <watan...@gmail.com>

Steven Watanabe

unread,
Aug 21, 2009, 4:01:38 PM8/21/09
to boost...@lists.boost.org
AMDG

Shaolin wrote:
> Ok, I have reconfigured it and the file is now located in the boost_1_39_0
> directory. However, it still doesnt work. This is what I type in command
> line:
>
> g++ -I /usr/local/boost_1_39_0 test.cc -o example \
> ~/stage/lib/libboost_thread-gcc43-mt-1_39.a
>

Does ~/stage/lib/libboost_thread-gcc43-mt-1_39.a exist?
From what you say below I doubt it, so of course it doesn't
work.

> *stage directory*:
> /usr/local/boost_1_39_0/stage/lib/libboost_thread-gcc43-mt-1_39.a
>

Assuming that this is the actual location of the library, use
-L/usr/local/boost_1_39_0/stage/lib -lboost_thread-gcc43-mt-1_39

Shaolin

unread,
Aug 21, 2009, 10:26:42 PM8/21/09
to boost...@lists.boost.org
Ok, the lib issues have been fixed. I have configured it all properly and I am not longer getting the 'dir not found errors'. I am alas getting a new error.

// This is what I enter in commandline
$ g++ -I /usr/local/boost_1_39_0 filereader.cc -o fr -L~/usr/local/boost_1_39_0/boost/stage/lib/libboost_thread-gcc43-mt-1_39.a

// ERROR MSG:
/tmp/ccv0fHxn.o: In function `main':
filereader.cc:(.text+0x3f0): undefined reference to `boost::thread::~thread()'
/tmp/ccv0fHxn.o: In function `boost::mutex::mutex()':
filereader.cc:(.text._ZN5boost5mutexC1Ev[boost::mutex::mutex()]+0x45): undefined reference to `boost::thread_resource_error::thread_resource_error()'
filereader.cc:(.text._ZN5boost5mutexC1Ev[boost::mutex::mutex()]+0x4d): undefined reference to `boost::thread_resource_error::~thread_resource_error()'
filereader.cc:(.text._ZN5boost5mutexC1Ev[boost::mutex::mutex()]+0x55): undefined reference to `typeinfo for boost::thread_resource_error'
/tmp/ccv0fHxn.o: In function `boost::detail::thread_data<void (*)()>::~thread_data()':
filereader.cc:(.text._ZN5boost6detail11thread_dataIPFvvEED0Ev[boost::detail::thread_data<void (*)()>::~thread_data()]+0x16): undefined reference to `boost::detail::thread_data_base::~thread_data_base()'
/tmp/ccv0fHxn.o: In function `boost::detail::thread_data<void (*)()>::~thread_data()':
filereader.cc:(.text._ZN5boost6detail11thread_dataIPFvvEED1Ev[boost::detail::thread_data<void (*)()>::~thread_data()]+0x16): undefined reference to `boost::detail::thread_data_base::~thread_data_base()'
/tmp/ccv0fHxn.o: In function `boost::condition_variable::condition_variable()':
filereader.cc:(.text._ZN5boost18condition_variableC1Ev[boost::condition_variable::condition_variable()]+0x3a): undefined reference to `boost::thread_resource_error::thread_resource_error()'
filereader.cc:(.text._ZN5boost18condition_variableC1Ev[boost::condition_variable::condition_variable()]+0x42): undefined reference to `boost::thread_resource_error::~thread_resource_error()'
filereader.cc:(.text._ZN5boost18condition_variableC1Ev[boost::condition_variable::condition_variable()]+0x4a): undefined reference to `typeinfo for boost::thread_resource_error'
/tmp/ccv0fHxn.o: In function `boost::detail::thread_data_base::thread_data_base()':
filereader.cc:(.text._ZN5boost6detail16thread_data_baseC2Ev[boost::detail::thread_data_base::thread_data_base()]+0x1b): undefined reference to `vtable for boost::detail::thread_data_base'
/tmp/ccv0fHxn.o: In function `boost::thread::thread<void (*)()>(void (*)(), boost::disable_if<boost::is_convertible<void (*&)(), boost::detail::thread_move_t<void (*)()> >, boost::thread::dummy*>::type)':
filereader.cc:(.text._ZN5boost6threadC1IPFvvEEET_NS_10disable_ifINS_14is_convertibleIRS4_NS_6detail13thread_move_tIS4_EEEEPNS0_5dummyEE4typeE[boost::thread::thread<void (*)()>(void (*)(), boost::disable_if<boost::is_convertible<void (*&)(), boost::detail::thread_move_t<void (*)()> >, boost::thread::dummy*>::type)]+0x32): undefined reference to `boost::thread::start_thread()'
/tmp/ccv0fHxn.o:(.rodata._ZTIN5boost6detail11thread_dataIPFvvEEE[typeinfo for boost::detail::thread_data<void (*)()>]+0x8): undefined reference to `typeinfo for boost::detail::thread_data_base'

collect2: ld returned 1 exit status



2009/8/21 Steven Watanabe <watan...@gmail.com>

Michael Caisse

unread,
Aug 21, 2009, 10:45:42 PM8/21/09
to boost...@lists.boost.org
You are still not using your tools correctly. -L is for specifying a directory location.
The errors you are getting are because you are not linking the thread library.

Let me suggest that you take some time with a simple non-boost example and learn how the
compiler and linker work. The problems you are having are simply because you do not
understand your tools. I am sure there must be some good tutorials on basic compiling/linking
somewhere on the web.

Good luck
Michael


--

----------------------------------
Michael Caisse
Object Modeling Designs
www.objectmodelingdesigns.com

Reply all
Reply to author
Forward
0 new messages