Boost logo

Boost Users :

Subject: Re: [Boost-users] subject:[Thread] undefined reference to `boost::thread::thread......
From: Anthony Williams (anthony.ajw_at_[hidden])
Date: 2008-11-05 11:01:52


"xiaofeng liao" <gliaoxf_at_[hidden]> writes:

> I got undefefined reference errors while using thread libs, I reviewd
> some existing post
> on this subject, but still can't solve my problem.

> Then I compile it use the following cmd, very similar to the previous one
> " c++ -I /usr/local/boost_1_37_0 thre.cpp -o thre
> /usr/local/boost_1_37_0/lib/libboost_thread-gcc41-mt-1_37.a"
> but I got the following errors:
> -------------------------------------------------------------------------------------
> /usr/local/boost_1_37_0/lib/libboost_thread-gcc41-mt-1_37.a(thread.o):
> In function `boost::detail::set_current_thread_data(boost::detail::thread_data_base*)':
> thread.cpp:(.text+0x12a): undefined reference to `pthread_setspecific'

This is a clue: pthread_setspecific is part of the pthread library,
not Boost.Thread. On linux, the thread library depends on the pthreads
library, so you also need -lpthread on your command line.

c++ -I /usr/local/boost_1_37_0 thre.cpp -o thre \
/usr/local/boost_1_37_0/lib/libboost_thread-gcc41-mt-1_37.a -lpthread

You may also need a "-mthread" or "-mthreads" or "-pthread" compiler
switch to enable gcc to generate multi-thread compatible code.

Anthony

-- 
Anthony Williams
Author of C++ Concurrency in Action | http://www.manning.com/williams
Custom Software Development | http://www.justsoftwaresolutions.co.uk
Just Software Solutions Ltd, Registered in England, Company Number 5478976.
Registered Office: 15 Carrallack Mews, St Just, Cornwall, TR19 7UL, UK

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net