I installed the boost library on my ubuntu using sudo apt-get install libboost-all-dev .
Wikipedia example is not compiled:
#include <boost/thread/thread.hpp> #include <iostream> using namespace std; void hello_world() { cout << "Здравствуй, мир, я - thread!" << endl; } int main(int argc, char* argv[]) { boost::thread my_thread(&hello_world); my_thread.join(); return 0; } The compiler gives an error:
/tmp/ccq2zeuG.o: In function `__static_initialization_and_destruction_0(int, int)': ch.cpp:(.text+0xd4): undefined reference to `boost::system::generic_category()' ch.cpp:(.text+0xe0): undefined reference to `boost::system::generic_category()' ch.cpp:(.text+0xec): undefined reference to `boost::system::system_category()' /tmp/ccq2zeuG.o: In function `boost::thread_exception::thread_exception(int, char const*)': ch.cpp:(.text._ZN5boost16thread_exceptionC2EiPKc[_ZN5boost16thread_exceptionC5EiPKc]+0x23): undefined reference to `boost::system::system_category()' /tmp/ccq2zeuG.o: In function `boost::detail::thread_data_base::thread_data_base()': ch.cpp:(.text._ZN5boost6detail16thread_data_baseC2Ev[_ZN5boost6detail16thread_data_baseC5Ev]+0x1e): undefined reference to `vtable for boost::detail::thread_data_base' /tmp/ccq2zeuG.o: In function `boost::thread::start_thread()': ch.cpp:(.text._ZN5boost6thread12start_threadEv[_ZN5boost6thread12start_threadEv]+0x24): undefined reference to `boost::thread::start_thread_noexcept()' /tmp/ccq2zeuG.o: In function `boost::thread::~thread()': ch.cpp:(.text._ZN5boost6threadD2Ev[_ZN5boost6threadD5Ev]+0x15): undefined reference to `boost::thread::detach()' /tmp/ccq2zeuG.o: In function `boost::thread::get_id() const': ch.cpp:(.text._ZNK5boost6thread6get_idEv[_ZNK5boost6thread6get_idEv]+0x18): undefined reference to `boost::thread::native_handle()' /tmp/ccq2zeuG.o: In function `boost::thread::join()': ch.cpp:(.text._ZN5boost6thread4joinEv[_ZN5boost6thread4joinEv]+0x88): undefined reference to `boost::thread::join_noexcept()' /tmp/ccq2zeuG.o: In function `boost::detail::thread_data<void (*)()>::~thread_data()': ch.cpp:(.text._ZN5boost6detail11thread_dataIPFvvEED2Ev[_ZN5boost6detail11thread_dataIPFvvEED5Ev]+0x20): undefined reference to `boost::detail::thread_data_base::~thread_data_base()' /tmp/ccq2zeuG.o:(.rodata._ZTIN5boost6detail11thread_dataIPFvvEEE[_ZTIN5boost6detail11thread_dataIPFvvEEE]+0x10): undefined reference to `typeinfo for boost::detail::thread_data_base' collect2: error: ld returned 1 exit status How to compile programs that use boost?
g++ -lboost_thread -lboost_system ch.cpp -o ch- KoVadim