0
votes

I am having issues compiling asio code through visual studio linux project. I keep getting the following linking error :

Linking objects

1>D:\C++\test_beastboost\test_beastboost\obj\x64\Debug\main.o : error : In function boost::asio::detail::posix_event::posix_event()': 1>/usr/local/include/boost/asio/detail/impl/posix_event.ipp(42): error : undefined reference topthread_condattr_setclock' 1>D:\C++\test_beastboost\test_beastboost\obj\x64\Debug\main.o : error : In function boost::asio::detail::posix_thread::~posix_thread()': 1>/usr/local/include/boost/asio/detail/impl/posix_thread.ipp(35): error : undefined reference topthread_detach' 1>D:\C++\test_beastboost\test_beastboost\obj\x64\Debug\main.o : error : In function boost::asio::detail::posix_thread::join()': 1>/usr/local/include/boost/asio/detail/impl/posix_thread.ipp(42): error : undefined reference topthread_join' 1>D:\C++\test_beastboost\test_beastboost\obj\x64\Debug\main.o : error : In function boost::asio::detail::posix_thread::start_thread(boost::asio::detail::posix_thread::func_base*)': 1>/usr/local/include/boost/asio/detail/impl/posix_thread.ipp(60): error : undefined reference topthread_create' 1>D:\C++\test_beastboost\test_beastboost\obj\x64\Debug\main.o : error : In function boost::asio::detail::posix_signal_blocker::posix_signal_blocker()': 1>/usr/local/include/boost/asio/detail/posix_signal_blocker.hpp(43): error : undefined reference topthread_sigmask' 1>D:\C++\test_beastboost\test_beastboost\obj\x64\Debug\main.o : error : In function boost::asio::detail::posix_signal_blocker::~posix_signal_blocker()': 1>/usr/local/include/boost/asio/detail/posix_signal_blocker.hpp(50): error : undefined reference topthread_sigmask' 1>D:\C++\test_beastboost\test_beastboost\obj\x64\Debug\main.o : error : In function std::thread::thread<std::_Bind<void (*(boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::executor>))(boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::executor>&)>>(std::_Bind<void (*(boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::executor>))(boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::executor>&)>&&)': 1>/usr/include/c++/5/thread(137): error : undefined reference topthread_create' 1>collect2 : error : ld returned 1 exit status

I have compiled boost 1_70 and they're located within usr/local/include/boost and usr/local/lib.

For my linker I have the following :

-L/usr/local/lib/ -lboost_system

I also try adding -lboost_thread but I am using standard library thread anyway..

any suggestions?

should I just recompile my boost on ubuntu.

1

1 Answers

0
votes

if you are using cmake to compile your project u can use the following in your CMakeLists.txt file:

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")

FIND_PACKAGE( Boost 1.70 COMPONENTS REQUIRED date_time)
INCLUDE_DIRECTORIES( ${Boost_INCLUDE_DIR} )

ADD_EXECUTABLE( exe cpp.cpp )

target_include_directories(exe PRIVATE ${Boost_INCLUDE_DIRS})
TARGET_LINK_LIBRARIES( exe LINK_PUBLIC ${Boost_LIBRARIES} )

install(TARGETS exe RUNTIME DESTINATION bin)

this should fix sum bugs at least.

and if you don't use cmake with vscode I recommend you to watch how to cmake good playlist from vector-of-bool