Boost.Asio Binding Error

I am trying to access an external device through a serial port and want to use Boost.Asio for this suggestion. I created boost libraries for MinGw and compiled a regular expression example.

But I have problems compiling my code if I include something from Boost.Asio:

#include <boost/asio/serial_port.hpp>

int main() {

    return 0;
}

g++ -D _WIN32_WINNT=0x0501 -O0 -g3 -Wall -c -fmessage-length=0 -osrc\SerialPortTest.o ..\src\SerialPortTest.cpp
g++ -LC:\boost-libs\boost\bin.v2\libs\thread\build\gcc-mingw-4.5.2\release\link-static\threading-multi -LC:\boost-libs\boost\bin.v2\libs\system\build\gcc-mingw-4.5.2\release\link-static\threading-multi -oSerialPortTest.exe src\SerialPortTest.o -lboost_thread-mgw45-mt-1_48 -lboost_system-mgw45-mt-1_48
src\SerialPortTest.o: In function `ZN5boost4asio6detail17winsock_init_base7startupERNS2_4dataEhh':
c:/mingw/bin/../lib/gcc/mingw32/4.5.2/../../../../include/boost/asio/detail/impl/winsock_init.ipp:39: undefined reference to `WSAStartup@8'
src\SerialPortTest.o: In function `ZN5boost4asio6detail17winsock_init_base7cleanupERNS2_4dataE':
c:/mingw/bin/../lib/gcc/mingw32/4.5.2/../../../../include/boost/asio/detail/impl/winsock_init.ipp:48: undefined reference to `WSACleanup@0'
collect2: ld returned 1 exit status

For me, this is a communication problem, but I do not understand it.

+5
source share
2 answers

Add the -lws2_32 flag to communicate with the WinSockets library.

It can also be useful: MinGW Linker Error: winsock

+9
source

You will skip the wsock32 library. Add this to your dependencies and it should work.

0
source

All Articles