I am trying to use the Boost library in VSCode under Windows 10 WSL2 Ubuntu 20.04. All package installs are fresh installs
I am new to c++ and library management and have tried various options but am unable to get one to work.
I installed boost using:
sudo apt-get install libboost-all-dev
I am using g++ and followed a tutorial to get it up and running with windows 10 / wsl2 / ubuntu / g++ and have it compiling/running a base 'hello world' script.
I modified my tasks.json file as per other info on google to be:
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++ build active file",
"command": "/usr/bin/g++",
"args": [
"-fdiagnostics-color=always",
"-g",
"-I/usr/local/include",
"-L/usr/local/lib",
"-lboost_system",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
The linter(I know it is separate from the build) does not complain with:
#include <boost/beast/core.hpp>
#include <boost/beast/websocket.hpp>
#include <boost/asio/connect.hpp>
#include <boost/asio/ip/tcp.hpp>
using tcp = boost::asio::ip::tcp;
namespace websocket = boost::beast::websocket;
but when I try to build it I get:
Starting build...
/usr/bin/g++ -fdiagnostics-color=always -g -I/usr/local/include -L/usr/local/lib -lboost_system /home/laptop/cppbot/helloworld.cpp -o /home/laptop/cppbot/helloworld
/usr/bin/ld: /tmp/ccmv4tdX.o: in function `boost::asio::detail::posix_event::posix_event()':
/usr/include/boost/asio/detail/impl/posix_event.ipp:42: undefined reference to `pthread_condattr_setclock'
/usr/bin/ld: /tmp/ccmv4tdX.o: in function `boost::asio::detail::posix_thread::~posix_thread()':
/usr/include/boost/asio/detail/impl/posix_thread.ipp:35: undefined reference to `pthread_detach'
/usr/bin/ld: /tmp/ccmv4tdX.o: in function `boost::asio::detail::posix_thread::join()':
/usr/include/boost/asio/detail/impl/posix_thread.ipp:42: undefined reference to `pthread_join'
/usr/bin/ld: /tmp/ccmv4tdX.o: in function `boost::asio::detail::posix_thread::start_thread(boost::asio::detail::posix_thread::func_base*)':
/usr/include/boost/asio/detail/impl/posix_thread.ipp:59: undefined reference to `pthread_create'
/usr/bin/ld: /tmp/ccmv4tdX.o: in function `boost::asio::detail::posix_signal_blocker::posix_signal_blocker()':
/usr/include/boost/asio/detail/posix_signal_blocker.hpp:43: undefined reference to `pthread_sigmask'
/usr/bin/ld: /tmp/ccmv4tdX.o: in function `boost::asio::detail::posix_signal_blocker::~posix_signal_blocker()':
/usr/include/boost/asio/detail/posix_signal_blocker.hpp:50: undefined reference to `pthread_sigmask'
collect2: error: ld returned 1 exit status
It never makes it to the actual code and fails on the imports
Any help would be appreciated. Thanks