Fehler beim Linken von Programm mit boost/thread
-
Hi,
EDIT:
Habs grad selber glöst bekommenich hab ein Problem damit Boost/thread auf meinem Ubuntu System mit cmake zum laufen zu bekommen.
Hier ein minimalbeispiel:
//main.cpp #include <iostream> #include <boost/thread.hpp> void func(){ std::cout<<"Hello World"<<std::endl; } int main(int argc, char* argv[]){ boost::thread_group threads; boost::thread* th1 = new boost::thread(&func); boost::thread* th2 = new boost::thread(&func); threads.add_thread(th1); threads.add_thread(th2); threads.join_all(); return 0; }
#CMakeLists.txt cmake_minimum_required(VERSION 2.8.12) project(thread CXX) #EDIT: find_package( Boost REQUIRED COMPONENTS thread ) add_executable(${PROJECT_NAME} main.cpp) #EDIT: target_link_libraries(${PROJECT_NAME} ${Boost_LIBRARIES})
Meine Eingabe im Terminal ist folgende
cmake . make
Das make schlägt beim linken Fehl:
Auszug aus den Fehlermeldungen:[ 50%] Building CXX object CMakeFiles/thread.dir/main.cpp.o [100%] Linking CXX executable thread CMakeFiles/thread.dir/main.cpp.o: In Funktion `__static_initialization_and_destruction_0(int, int)': main.cpp:(.text+0x1b1): Nicht definierter Verweis auf `boost::system::generic_category()' main.cpp:(.text+0x1bd): Nicht definierter Verweis auf `boost::system::generic_category()' main.cpp:(.text+0x1c9): Nicht definierter Verweis auf `boost::system::system_category()' CMakeFiles/thread.dir/main.cpp.o: In Funktion `boost::thread_exception::thread_exception(int, char const*)': main.cpp:(.text._ZN5boost16thread_exceptionC2EiPKc[_ZN5boost16thread_exceptionC5EiPKc]+0x23): Nicht definierter Verweis auf `boost::system::system_category()' CMakeFiles/thread.dir/main.cpp.o: In Funktion `boost::condition_error::condition_error(int, char const*)':
Compiler ist (oder sollte sein??) g++ (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609
und boot wurde mittels
sudo apt-get install libboost-all-dev
installiertJemand eine Ahnung wie dieser Fehler zustande kommt? Ich hab von Boost/Linux/Cmake so gut wie keine Ahnung, muss es aber verwenden.
-
Du mußt die passenden Boost-Libs noch dazu linken, s. How to link C++ program with Boost using CMake.