
Hello ,every one. I got undefefined reference errors while using thread libs, I reviewd some existing post on this subject, but still can't solve my problem. So I paste my problem here, I appreciate any help. Thank you. My platform is fedora 8, gcc 4.1.2 20070925 (Red Hat 4.1.2-33). I downloaded boost_1_37_0.tar.bz2 from www.boost.org I followed the "Getting started guide" on the www.boost.org I extracted the boost_1_37_0.tar.bz2 use "tar --bzip2 -xf /usr/local/boost_1_37_0.tar.bz2"; Because I want to write multi-thread programs using boost, so I decided to build the separately-compiled Boost libraries. I followed the "Getting Started Guide". I run the following cmds: ./configure --prefix=/usr/local/boost_1_37_0/ make install So, after long wait, it's done, all the librarys are build. My /usr/local/boost_1_37_0 directory structure looks like this: ----------------------------------------------------------------------------------- drwxr-xr-x 3 root root 4096 11-03 16:51 bin.v2 drwxr-xr-x 69 1000 1000 4096 11-02 20:50 boost -rw-r--r-- 1 1000 1000 848 06-26 23:57 boost-build.jam -rw-r--r-- 1 1000 1000 969 2006-12-02 boost.css -rw-r--r-- 1 1000 1000 6308 2005-08-12 boost.png -rwxr-xr-x 1 1000 1000 9909 2008-04-30 configure -rw-r--r-- 1 root root 0 11-05 22:05 dir drwxr-xr-x 4 1000 1000 4096 11-02 21:05 doc drwxr-xr-x 3 root root 4096 11-03 16:51 include -rw-r--r-- 1 1000 1000 770 2008-02-22 index.htm -rw-r--r-- 1 1000 1000 5505 10-20 21:20 index.html -rw-r--r-- 1 1000 1000 291 2008-03-27 INSTALL -rw-r--r-- 1 1000 1000 16934 11-01 21:14 Jamroot drwxr-xr-x 2 root root 12288 11-03 17:14 lib drwxr-xr-x 80 1000 1000 4096 11-02 20:53 libs -rw-r--r-- 1 1000 1000 1338 2003-09-30 LICENSE_1_0.txt -rw-r--r-- 1 root root 1026 11-03 19:57 Makefile drwxr-xr-x 4 1000 1000 4096 11-02 20:53 more drwxr-xr-x 2 1000 1000 4096 11-02 20:49 people -rw-r--r-- 1 1000 1000 2610 2008-03-23 rst.css drwxr-xr-x 2 1000 1000 4096 11-02 20:49 status drwxr-xr-x 13 1000 1000 4096 11-02 20:53 tools -rw-r--r-- 1 root root 165 11-03 16:49 user-config.jam -rw-r--r-- 1 root root 113 11-03 16:47 user-config.jam.1 drwxr-xr-x 2 1000 1000 4096 11-02 20:53 wiki ---------------------------------------------------------------------------------- I test the regex library by running the program from the "Getting Started Guide", which links the regex library. I named the program regex.cpp. Following is the cmd I used to compile the program. "c++ -I /usr/local/boost_1_37_0 regex.cpp -o regex /usr/local/boost_1_37_0/lib/libboost_regex-gcc41-mt-1_37.a" There is no error occurs. Then, I write another program trying to use the thread library. I named this program thre.cpp. Following is my program, a very simple one: ----------------------------------------------------------------------------- #include <boost/thread.hpp> #include <iostream> void hello() { std::cout<<std::endl<<"hello world, I'm a thread!"<<std::endl; } int main() { boost::thread thrd(&hello); thrd.join(); return 0; } ------------------------------------------------------------------------------------ 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' /usr/local/boost_1_37_0/lib/libboost_thread-gcc41-mt-1_37.a(thread.o): In function `boost::detail::(anonymous namespace)::create_current_thread_tls_key()': thread.cpp:(.text+0x146): undefined reference to `pthread_key_create' /usr/local/boost_1_37_0/lib/libboost_thread-gcc41-mt-1_37.a(thread.o): In function `boost::detail::get_current_thread_data()': thread.cpp:(.text+0x173): undefined reference to `pthread_getspecific' /usr/local/boost_1_37_0/lib/libboost_thread-gcc41-mt-1_37.a(thread.o): In function `boost::thread::start_thread()': thread.cpp:(.text+0x648): undefined reference to `pthread_create' /usr/local/boost_1_37_0/lib/libboost_thread-gcc41-mt-1_37.a(thread.o): In function `boost::thread::detach()': thread.cpp:(.text+0x79f): undefined reference to `pthread_detach' /usr/local/boost_1_37_0/lib/libboost_thread-gcc41-mt-1_37.a(thread.o): In function `thread_proxy': thread.cpp:(.text+0x9ce): undefined reference to `pthread_setspecific' thread.cpp:(.text+0xa0d): undefined reference to `pthread_setspecific' /usr/local/boost_1_37_0/lib/libboost_thread-gcc41-mt-1_37.a(thread.o): In function `boost::(anonymous namespace)::make_external_thread_data()': thread.cpp:(.text+0xe84): undefined reference to `pthread_setspecific' /usr/local/boost_1_37_0/lib/libboost_thread-gcc41-mt-1_37.a(thread.o): In function `boost::detail::find_tss_data(void const*)': thread.cpp:(.text+0x1427): undefined reference to `pthread_getspecific' /usr/local/boost_1_37_0/lib/libboost_thread-gcc41-mt-1_37.a(thread.o): In function `boost::this_thread::restore_interruption::~restore_interruption()': thread.cpp:(.text+0x1493): undefined reference to `pthread_getspecific' thread.cpp:(.text+0x14b8): undefined reference to `pthread_getspecific' /usr/local/boost_1_37_0/lib/libboost_thread-gcc41-mt-1_37.a(thread.o): In function `boost::this_thread::restore_interruption::~restore_interruption()': thread.cpp:(.text+0x14f3): undefined reference to `pthread_getspecific' thread.cpp:(.text+0x1518): undefined reference to `pthread_getspecific' /usr/local/boost_1_37_0/lib/libboost_thread-gcc41-mt-1_37.a(thread.o):thread.cpp:(.text+0x155d): more undefined references to `pthread_getspecific' follow /usr/local/boost_1_37_0/lib/libboost_thread-gcc41-mt-1_37.a(thread.o): In function `boost::thread::join()': thread.cpp:(.text+0x1be9): undefined reference to `pthread_join' /usr/local/boost_1_37_0/lib/libboost_thread-gcc41-mt-1_37.a(thread.o): In function `boost::detail::set_tss_data(void const*, boost::shared_ptr<boost::detail::tss_cleanup_function>, void*, bool)': thread.cpp:(.text+0x1f5d): undefined reference to `pthread_getspecific' /usr/local/boost_1_37_0/lib/libboost_thread-gcc41-mt-1_37.a(thread.o): In function `boost::detail::get_tss_data(void const*)': thread.cpp:(.text+0x2137): undefined reference to `pthread_getspecific' /usr/local/boost_1_37_0/lib/libboost_thread-gcc41-mt-1_37.a(thread.o): In function `boost::this_thread::disable_interruption::disable_interruption()': thread.cpp:(.text+0x2197): undefined reference to `pthread_getspecific' thread.cpp:(.text+0x21d1): undefined reference to `pthread_getspecific' /usr/local/boost_1_37_0/lib/libboost_thread-gcc41-mt-1_37.a(thread.o): In function `boost::this_thread::disable_interruption::disable_interruption()': thread.cpp:(.text+0x2217): undefined reference to `pthread_getspecific' /usr/local/boost_1_37_0/lib/libboost_thread-gcc41-mt-1_37.a(thread.o):thread.cpp:(.text+0x2251): more undefined references to `pthread_getspecific' follow /usr/local/boost_1_37_0/lib/libboost_thread-gcc41-mt-1_37.a(thread.o): In function `boost::thread::timed_join(boost::posix_time::ptime const&)': thread.cpp:(.text+0x237a): undefined reference to `pthread_join' /usr/local/boost_1_37_0/lib/libboost_thread-gcc41-mt-1_37.a(thread.o): In function `boost::condition_variable::timed_wait(boost::unique_lock<boost::mutex>&, boost::posix_time::ptime const&)': thread.cpp:(.text._ZN5boost18condition_variable10timed_waitERNS_11unique_lockINS_5mutexEEERKNS_10posix_time5ptimeE[boost::condition_variable::timed_wait(boost::unique_lock<boost::mutex>&, boost::posix_time::ptime const&)]+0x26): undefined reference to `pthread_getspecific' /usr/local/boost_1_37_0/lib/libboost_thread-gcc41-mt-1_37.a(once.o): In function `boost::detail::get_once_per_thread_epoch()': once.cpp:(.text+0x17): undefined reference to `pthread_once' once.cpp:(.text+0x24): undefined reference to `pthread_getspecific' once.cpp:(.text+0x4d): undefined reference to `pthread_setspecific' /usr/local/boost_1_37_0/lib/libboost_thread-gcc41-mt-1_37.a(once.o): In function `create_epoch_tss_key': once.cpp:(.text+0x86): undefined reference to `pthread_key_create' collect2: ld 返回 1 ------------------------------------------------------------------------------------- But in fact ,in the lib directory , there exist the thread libs, they are: ------------------------------------------------------------------------------------- /usr/local/boost_1_37_0/lib/libboost_thread-gcc41-mt.a /usr/local/boost_1_37_0/lib/libboost_thread-gcc41-mt.so /usr/local/boost_1_37_0/lib/libboost_thread-gcc41-mt-1_37.a /usr/local/boost_1_37_0/lib/libboost_thread-gcc41-mt-1_37.so /usr/local/boost_1_37_0/lib/libboost_thread-gcc41-mt-1_37.so.1.37.0 ------------------------------------------------------------------------------------- I also tried another cmds on these two programs, they are: "g++ -o regex -lz regex.cpp /usr/local/boost_1_37_0/lib/libboost_regex-gcc41-mt-1_37.a" "g++ -o thre -lz thre.cpp /usr/local/boost_1_37_0/lib/libboost_thread-gcc41-mt-1_37.a" the regex cmd runs ok, but the thre cmd again failed. Got the following errors: ------------------------------------------------------------------------------------ thre.cpp:(.text+0xad): undefined reference to `boost::thread::thread(boost::function0<void, std::allocator<boost::function_base> > const&)' /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' /usr/local/boost_1_37_0/lib/libboost_thread-gcc41-mt-1_37.a(thread.o): In function `boost::detail::(anonymous namespace)::create_current_thread_tls_key()': thread.cpp:(.text+0x146): undefined reference to `pthread_key_create' /usr/local/boost_1_37_0/lib/libboost_thread-gcc41-mt-1_37.a(thread.o): In function `boost::detail::get_current_thread_data()': thread.cpp:(.text+0x173): undefined reference to `pthread_getspecific' /usr/local/boost_1_37_0/lib/libboost_thread-gcc41-mt-1_37.a(thread.o): In function `boost::thread::start_thread()': thread.cpp:(.text+0x648): undefined reference to `pthread_create' /usr/local/boost_1_37_0/lib/libboost_thread-gcc41-mt-1_37.a(thread.o): In function `boost::thread::detach()': thread.cpp:(.text+0x79f): undefined reference to `pthread_detach' /usr/local/boost_1_37_0/lib/libboost_thread-gcc41-mt-1_37.a(thread.o): In function `thread_proxy': thread.cpp:(.text+0x9ce): undefined reference to `pthread_setspecific' thread.cpp:(.text+0xa0d): undefined reference to `pthread_setspecific' /usr/local/boost_1_37_0/lib/libboost_thread-gcc41-mt-1_37.a(thread.o): In function `boost::(anonymous namespace)::make_external_thread_data()': thread.cpp:(.text+0xe84): undefined reference to `pthread_setspecific' /usr/local/boost_1_37_0/lib/libboost_thread-gcc41-mt-1_37.a(thread.o): In function `boost::detail::find_tss_data(void const*)': thread.cpp:(.text+0x1427): undefined reference to `pthread_getspecific' /usr/local/boost_1_37_0/lib/libboost_thread-gcc41-mt-1_37.a(thread.o): In function `boost::this_thread::restore_interruption::~restore_interruption()': thread.cpp:(.text+0x1493): undefined reference to `pthread_getspecific' thread.cpp:(.text+0x14b8): undefined reference to `pthread_getspecific' /usr/local/boost_1_37_0/lib/libboost_thread-gcc41-mt-1_37.a(thread.o): In function `boost::this_thread::restore_interruption::~restore_interruption()': thread.cpp:(.text+0x14f3): undefined reference to `pthread_getspecific' thread.cpp:(.text+0x1518): undefined reference to `pthread_getspecific' /usr/local/boost_1_37_0/lib/libboost_thread-gcc41-mt-1_37.a(thread.o):thread.cpp:(.text+0x155d): more undefined references to `pthread_getspecific' follow /usr/local/boost_1_37_0/lib/libboost_thread-gcc41-mt-1_37.a(thread.o): In function `boost::thread::join()': thread.cpp:(.text+0x1be9): undefined reference to `pthread_join' /usr/local/boost_1_37_0/lib/libboost_thread-gcc41-mt-1_37.a(thread.o): In function `boost::detail::set_tss_data(void const*, boost::shared_ptr<boost::detail::tss_cleanup_function>, void*, bool)': thread.cpp:(.text+0x1f5d): undefined reference to `pthread_getspecific' /usr/local/boost_1_37_0/lib/libboost_thread-gcc41-mt-1_37.a(thread.o): In function `boost::detail::get_tss_data(void const*)': thread.cpp:(.text+0x2137): undefined reference to `pthread_getspecific' /usr/local/boost_1_37_0/lib/libboost_thread-gcc41-mt-1_37.a(thread.o): In function `boost::this_thread::disable_interruption::disable_interruption()': thread.cpp:(.text+0x2197): undefined reference to `pthread_getspecific' thread.cpp:(.text+0x21d1): undefined reference to `pthread_getspecific' /usr/local/boost_1_37_0/lib/libboost_thread-gcc41-mt-1_37.a(thread.o): In function `boost::this_thread::disable_interruption::disable_interruption()': thread.cpp:(.text+0x2217): undefined reference to `pthread_getspecific' /usr/local/boost_1_37_0/lib/libboost_thread-gcc41-mt-1_37.a(thread.o):thread.cpp:(.text+0x2251): more undefined references to `pthread_getspecific' follow /usr/local/boost_1_37_0/lib/libboost_thread-gcc41-mt-1_37.a(thread.o): In function `boost::thread::timed_join(boost::posix_time::ptime const&)': thread.cpp:(.text+0x237a): undefined reference to `pthread_join' /usr/local/boost_1_37_0/lib/libboost_thread-gcc41-mt-1_37.a(thread.o): In function `boost::condition_variable::timed_wait(boost::unique_lock<boost::mutex>&, boost::posix_time::ptime const&)': thread.cpp:(.text._ZN5boost18condition_variable10timed_waitERNS_11unique_lockINS_5mutexEEERKNS_10posix_time5ptimeE[boost::condition_variable::timed_wait(boost::unique_lock<boost::mutex>&, boost::posix_time::ptime const&)]+0x26): undefined reference to `pthread_getspecific' /usr/local/boost_1_37_0/lib/libboost_thread-gcc41-mt-1_37.a(once.o): In function `boost::detail::get_once_per_thread_epoch()': once.cpp:(.text+0x17): undefined reference to `pthread_once' once.cpp:(.text+0x24): undefined reference to `pthread_getspecific' once.cpp:(.text+0x4d): undefined reference to `pthread_setspecific' /usr/local/boost_1_37_0/lib/libboost_thread-gcc41-mt-1_37.a(once.o): In function `create_epoch_tss_key': once.cpp:(.text+0x86): undefined reference to `pthread_key_create' collect2: ld 返回 1 --------------------------------------------------------------------------------- I attatched my makefile, hope it give some cues. Thank you for your patience reading so long a post. -- Xiaofeng Liao