When I am compiling a Boost.asio program with the code:
g++ -o main main.cpp -lboost_system -lboost_thread -pthread
It just works fine, but if I compile it for windows on linux system as an executable with the code:
x86_64-w64-mingw32-g++ -I /usr/include/boost -o main.exe main.cpp -lboost_system -lboost_thread -pthread
or
x86_64-w64-mingw32-g++ -o main.exe main.cpp -lboost_system -lboost_thread -pthread
There is a compile Error
fatal error: boost/asio/io_service.hpp: No such file or directory
#include <boost/asio/io_service.hpp>
I mean I tried so many things to solve it and it makes me so angry do you know why?
When it comes to Windows, you should add the winsockets libraries as a compilation parameter.
g++ -o main.exe main.cpp -lboost_system -lboost_thread -pthread -lws2_32 -lwsock32
Normally only "ws2_32" is enough.
Note: Winsock2 (ws2_32) is an extension to Winsock1 (wsock32). A program that currently works against wsock32 should still work fine when relinked against ws2_32.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.