1

I am trying to use asio library for networking in c++ but I have failed to load it. I am using visual studio code, mingw/g++ This is the path to my include folder -> C:\msys64\mingw64\include Here is the code in my main file.

#include <iostream>
#include <asio.hpp>
#include <asio/ts/buffer.hpp>
#include <asio/ts/internet.hpp>

int main()
{
    return 0;
}
This is the result of compilation

C:\Users\2022\Desktop\TUTORIALS\C++\SocketsTutorial>g++ main.cpp -o main.exe -I C:\Users\2022\Downloads\asio-1.24.0\asio-1.24.0\include
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\2022\AppData\Local\Temp\cc33Br48.o:main.cpp:(.text$_ZN4asio6detail17winsock_init_base7startupERNS1_4dataEhh[_ZN4asio6detail17winsock_init_base7startupERNS1_4dataEhh]+0x74): undefined reference to `__imp_WSAStartup'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\2022\AppData\Local\Temp\cc33Br48.o:main.cpp:(.text$_ZN4asio6detail17winsock_init_base7cleanupERNS1_4dataE[_ZN4asio6detail17winsock_init_base7cleanupERNS1_4dataE]+0x35): undefined reference to `__imp_WSACleanup'
collect2.exe: error: ld returned 1 exit status

Thank you in advance :)

Eric Postpischil
  • 195,579
  • 13
  • 168
  • 312
jamie_0101
  • 35
  • 3
  • You should add compilation command that generates the error. Also you can check [this answer](https://stackoverflow.com/a/12472772/12463055) for solution of similar question. – erenalyoruk Nov 06 '22 at 11:22
  • This is the command -> g++ main.cpp -o main.exe -I C:\Users\2022\Downloads\asio-1.24.0\asio-1.24.0\include – jamie_0101 Nov 06 '22 at 11:25
  • You should add library called `ws2_32` for Windows socket. The final command should be `g++ main.cpp -o main.exe -I C:\Users\2022\Downloads\asio-1.24.0\asio-1.24.0\include -lws2_32`. I have never used that asio library but it should be work. – erenalyoruk Nov 06 '22 at 11:35
  • I love you bro you have saved my life – jamie_0101 Nov 06 '22 at 11:45

0 Answers0