Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Boost.Asio linking error

Tags:

c++

mingw

boost

I'm trying access an extern device via a serial port and want to use Boost.Asio for this propose. I have build the boost libraries for MinGw and compiled the regex example successful.

But I have problems to compile 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 it seems to be a linking problem, but I don't get it.

like image 741
viktorgt Avatar asked Jan 11 '12 15:01

viktorgt


1 Answers

Add -lws2_32 flag to link against WinSockets library.

Also, this might be useful: MinGW linker error: winsock

like image 118
Alex Kremer Avatar answered Sep 28 '22 16:09

Alex Kremer