boost - Static Compile of Thread Example -
i compiled boost c++ libraries follows:
bjam install variant=release link=static threading=multi runtime-link=static
no errors. compiled following source:
#include <boost/thread/thread.hpp> #include <iostream> #define boost_thread_no_lib void hello() { std::cout << "hello world, i'm thread!" << std::endl; } int main(int argc, char* argv[]) { boost::thread thrd(&hello); thrd.join(); return 0; }
using:
g++ -lboost_thread thread.cpp
the program compiled , ran fine because boost libraries found in /usr/local/lib
. when removed /usr/local/lib
/etc/ld.so.conf.d/libc.conf
ran following error (no surpise):
./a.out: error while loading shared libraries: libboost_thread.so.1.41.0: cannot open shared object file: no such file or directory
how compile thread.cpp
linking boost statically? tried following:
g++ -static -lboost_thread -lpthread thread.cpp
i have following boost libraries installed:
ldconfig -v | grep boost libboost_unit_test_framework.so.1.41.0 -> libboost_unit_test_framework.so.1.41.0 libboost_math_tr1f.so.1.41.0 -> libboost_math_tr1f.so.1.41.0 libboost_prg_exec_monitor.so.1.41.0 -> libboost_prg_exec_monitor.so.1.41.0 libboost_math_c99.so.1.41.0 -> libboost_math_c99.so.1.41.0 libboost_regex.so.1.41.0 -> libboost_regex.so.1.41.0 libboost_signals.so.1.41.0 -> libboost_signals.so.1.41.0 libboost_python.so.1.41.0 -> libboost_python.so.1.41.0 libboost_serialization.so.1.41.0 -> libboost_serialization.so.1.41.0 libboost_graph.so.1.41.0 -> libboost_graph.so.1.41.0 libboost_date_time.so.1.41.0 -> libboost_date_time.so.1.41.0 libboost_thread.so.1.41.0 -> libboost_thread.so.1.41.0 libboost_math_c99l.so.1.41.0 -> libboost_math_c99l.so.1.41.0 libboost_math_tr1l.so.1.41.0 -> libboost_math_tr1l.so.1.41.0 libboost_wserialization.so.1.41.0 -> libboost_wserialization.so.1.41.0 libboost_system.so.1.41.0 -> libboost_system.so.1.41.0 libboost_math_tr1.so.1.41.0 -> libboost_math_tr1.so.1.41.0 libboost_math_c99f.so.1.41.0 -> libboost_math_c99f.so.1.41.0 libboost_wave.so.1.41.0 -> libboost_wave.so.1.41.0 libboost_filesystem.so.1.41.0 -> libboost_filesystem.so.1.41.0 libboost_program_options.so.1.41.0 -> libboost_program_options.so.1.41.0 libboost_program_options.so.1.35.0 -> libboost_program_options.so.1.35.0 libboost_program_options-mt.so.1.35.0 -> libboost_program_options-mt.so.1.35.0 libboost_thread-gcc42-mt-1_34_1.so.1.34.1 -> libboost_thread-gcc42-mt-1_34_1.so.1.34.1
i receive following compile errors:
/tmp/ccek8br2.o: in function `main': thread.cpp:(.text+0x10b): undefined reference `boost::thread::join()' thread.cpp:(.text+0x119): undefined reference `boost::thread::~thread()' thread.cpp:(.text+0x140): undefined reference `boost::thread::~thread()' /tmp/ccek8br2.o: in function `boost::mutex::mutex()': thread.cpp:(.text._zn5boost5mutexc1ev[boost::mutex::mutex()]+0x22): undefined reference `pthread_mutex_init' /tmp/ccek8br2.o: in function `boost::detail::thread_data<void (*)()>::~thread_data()': thread.cpp:(.text._zn5boost6detail11thread_dataipfvveed0ev[boost::detail::thread_data<void (*)()>::~thread_data()]+0x1c): undefined reference `boost::detail::thread_data_base::~thread_data_base()' /tmp/ccek8br2.o: in function `boost::detail::thread_data<void (*)()>::~thread_data()': thread.cpp:(.text._zn5boost6detail11thread_dataipfvveed1ev[boost::detail::thread_data<void (*)()>::~thread_data()]+0x1c): undefined reference `boost::detail::thread_data_base::~thread_data_base()' /tmp/ccek8br2.o: in function `boost::condition_variable::condition_variable()': thread.cpp:(.text._zn5boost18condition_variablec1ev[boost::condition_variable::condition_variable()]+0x17): undefined reference `pthread_cond_init' /tmp/ccek8br2.o: in function `boost::condition_variable::~condition_variable()': thread.cpp:(.text._zn5boost18condition_variabled1ev[boost::condition_variable::~condition_variable()]+0x11): undefined reference `pthread_cond_destroy' /tmp/ccek8br2.o: in function `boost::mutex::~mutex()': thread.cpp:(.text._zn5boost5mutexd1ev[boost::mutex::~mutex()]+0x11): undefined reference `pthread_mutex_destroy' /tmp/ccek8br2.o: in function `boost::detail::thread_data_base::thread_data_base()': thread.cpp:(.text._zn5boost6detail16thread_data_basec2ev[boost::detail::thread_data_base::thread_data_base()]+0x23): undefined reference `vtable boost::detail::thread_data_base' /tmp/ccek8br2.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)': thread.cpp:(.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)]+0x36): undefined reference `boost::thread::start_thread()' /tmp/ccek8br2.o:(.rodata._ztin5boost6detail11thread_dataipfvveee[typeinfo boost::detail::thread_data<void (*)()>]+0x10): undefined reference `typeinfo boost::detail::thread_data_base' collect2: ld returned 1 exit status
any ideas?
try:
g++ -static -pthread thread.cpp -lboost_thread
libraries must specified after objects (or sources) use symbols libraries.
Comments
Post a Comment