So i was just messing around boost.asio. They have a pretty nice tutorial page, where i just followed the instructions and pretty much copied the code. Previous examples are working just fine, but when it comes to threads i get bunch of errors
FAILED: untitled
: && /usr/bin/c++ -lboost_system -g CMakeFiles/untitled.dir/main.cpp.o -o untitled && :
/usr/bin/ld: CMakeFiles/untitled.dir/main.cpp.o: warning: relocation against `_ZTVN5boost6detail16thread_data_baseE' in read-only section `.text._ZN5boost6detail16thread_data_baseC2Ev[_ZN5boost6detail16thread_data_baseC5Ev]'
/usr/bin/ld: CMakeFiles/untitled.dir/main.cpp.o: in function `boost::detail::thread_data_base::thread_data_base()':
/home/user_me/Sys_Builds/boost_1_79_0/boost/thread/pthread/thread_data.hpp:162: undefined reference to `vtable for boost::detail::thread_data_base'
/usr/bin/ld: CMakeFiles/untitled.dir/main.cpp.o: in function `boost::thread::start_thread()':
/home/user_me/Sys_Builds/boost_1_79_0/boost/thread/detail/thread.hpp:182: undefined reference to `boost::thread::start_thread_noexcept()'
/usr/bin/ld: CMakeFiles/untitled.dir/main.cpp.o: in function `boost::thread::~thread()':
.
.
.
I use the boost 1-79-0. I downloaded binaries from official website and run basically two commands inside of the directory
./bootstrap.sh
./b2 install
After this i just added the line
include_directories("/home/user_me/Sys_Builds/boost_1_79_0")
to cmake (i use clion as IDE). As said before, it seems like everything is working just fine but threads (which is pretty weird).
In case you're just waiting to markup this post as duplicate - i've came across 4 or 5 similarish posts on varius sites and nothing has worked for me.
Solution
As you can read in the comments i was including only header files hence problem with linking the library. Using the link (to post where i should've found the solution before making another) provided #btdrescherjm i rewrote the CMakeLists.txt to#Project details
cmake_minimum_required(VERSION 3.22)
project(untitled)
#Setting cmake standard
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
#Boost config section
find_package(Boost COMPONENTS thread REQUIRED)
#Adding exec
add_executable(
${PROJECT_NAME}
main.cpp
)
target_link_libraries(
${PROJECT_NAME}
Boost::thread
)