简体   繁体   English

使用 boost.asio 在 linux 系统上编译 mingw32 可执行文件的问题

[英]Problem with compiling a mingw32 executable on linux system with boost.asio

When I am compiling a Boost.asio program with the code:当我使用代码编译 Boost.asio 程序时:

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:它工作正常,但如果我将它编译为 linux 系统上的 windows 为可执行文件:

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.当涉及到 Windows 时,您应该添加winsockets库作为编译参数。

g++ -o main.exe main.cpp -lboost_system -lboost_thread -pthread -lws2_32 -lwsock32

Normally only "ws2_32" is enough.通常只有“ws2_32”就足够了。

Note: Winsock2 (ws2_32) is an extension to Winsock1 (wsock32).注意: Winsock2 (ws2_32) 是 Winsock1 (wsock32) 的扩展。 A program that currently works against wsock32 should still work fine when relinked against ws2_32.当前适用于 wsock32 的程序在重新链接到 ws2_32 时应该仍然可以正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM