Newbie - Using Boost ASIO and Boost Thread from CMake based project

Hello,
I am implementing a serial port protocol in a Linux based library. We build boost ourselves (1.86.0) for inclusion in thrift so I am trying to use as much as I can just from the Boost libraries to gain some experience with them.
My serial port driver is using the serial_port class from Boost ASIO. It's super cool and working well. To include Boost ASIO in my CMake target, all I have done is this:
cmake_minimum_required(VERSION 3.30)
set(CMAKE_CXX_STANDARD 20)
set(BOOST_ROOT "${PROJECT_SOURCE_DIR}/../dataman_service/boost-install-x86_64-Debug/")
find_package(Boost CONFIG)
#This is an alternate use?
#find_package(Boost NO_MODULE)
add_library(L2PUtility
L2Packet.cpp
L1Transport.cpp
crc1021.cpp)
target_include_directories(L2PUtility PUBLIC ${CMAKE_SOURCE_DIR} ${BOOST_ROOT}/include)
Note there is no target_link_libraries, but ASIO works. I thought that was because it's an HPP/Header only implementation?
Since I need to add some threading to the project, I thought I would use the boost_thread library. Examples online show the inclusion of boost/thread.hpp, so I assumed it is another header only implementation and no link library is needed but I am getting a linking error:
[2/4] Linking CXX executable L2PSecondary
FAILED: L2PSecondary
: && /usr/bin/c++ -g CMakeFiles/L2PSecondary.dir/main.cpp.o -o L2PSecondary libL2PUtility.a && :
/usr/bin/ld: libL2PUtility.a(L1Transport.cpp.o): warning: relocation against `_ZTVN5boost6detail16thread_data_baseE' in read-only section `.text._ZN5boost6detail16thread_data_baseC2Ev[_ZN5boost6detail16thread_data_baseC5Ev]'
/usr/bin/ld: libL2PUtility.a(L1Transport.cpp.o): in function `L1Transport::start_detached()':
/home/rhaley/tuleap/BoostAsioL2p/L1Transport.cpp:440:(.text+0x1b32): undefined reference to `boost::thread::detach()'
/usr/bin/ld: libL2PUtility.a(L1Transport.cpp.o): in function `boost::detail::thread_data_base::thread_data_base()':
/home/rhaley/tuleap/BoostAsioL2p/../stroma_dataman_service/boost-install-x86_64-Debug/include/boost/thread/pthread/thread_data.hpp:162:(.text._ZN5boost6detail16thread_data_baseC2Ev[_ZN5boost6detail16thread_data_baseC5Ev]+0x24): undefined reference to `vtable for boost::detail::thread_data_base'
/usr/bin/ld: libL2PUtility.a(L1Transport.cpp.o): in function `boost::thread::start_thread()':
/home/rhaley/tuleap/BoostAsioL2p/../stroma_dataman_service/boost-install-x86_64-Debug/include/boost/thread/detail/thread.hpp:182:(.text._ZN5boost6thread12start_threadEv[_ZN5boost6thread12start_threadEv]+0x28): undefined reference to `boost::thread::start_thread_noexcept()'
/usr/bin/ld: libL2PUtility.a(L1Transport.cpp.o): in function `boost::thread::~thread()':
/home/rhaley/tuleap/BoostAsioL2p/../stroma_dataman_service/boost-install-x86_64-Debug/include/boost/thread/detail/thread.hpp:257:(.text._ZN5boost6threadD2Ev[_ZN5boost6threadD5Ev]+0x18): undefined reference to `boost::thread::detach()'
/usr/bin/ld: libL2PUtility.a(L1Transport.cpp.o): in function `boost::thread::get_id() const':
/home/rhaley/tuleap/BoostAsioL2p/../stroma_dataman_service/boost-install-x86_64-Debug/include/boost/thread/detail/thread.hpp:738:(.text._ZNK5boost6thread6get_idEv[_ZNK5boost6thread6get_idEv]+0x27): undefined reference to `boost::thread::native_handle()'
/usr/bin/ld: libL2PUtility.a(L1Transport.cpp.o): in function `boost::thread::join()':
/home/rhaley/tuleap/BoostAsioL2p/../stroma_dataman_service/boost-install-x86_64-Debug/include/boost/thread/detail/thread.hpp:762:(.text._ZN5boost6thread4joinEv[_ZN5boost6thread4joinEv]+0x90): undefined reference to `boost::thread::join_noexcept()'
/usr/bin/ld: libL2PUtility.a(L1Transport.cpp.o): in function `boost::detail::thread_data
participants (1)
-
Russell Haley