错误:在使用Boost 1.82和MINGW编译示例Boost ASIO程序时发生错误。

huangapple go评论57阅读模式
英文:

Error when compiling a sample Boost ASIO program using boost 1.82 and MINGW

问题

以下是您提供的内容的翻译:

我正在尝试编译给出的绝对基本的ASIO教程代码,位于这里

我正在使用MINGW 64进行编译。
但是,我在终端中遇到了一堆链接错误:

启动构建...
D:\mingw64\bin\g++.exe -fdiagnostics-color=always -g -I D:\boost\boost_1_82_0
"D:\Development\simplefolder\simpleclient.cpp" -o "D:\Development\surviving mars\simplefolder\simpleclient.exe"
D:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\MUHAMM~1\AppData\Local\Temp\cc44Ri3w.o: 在函数中 `boost::asio::detail::winsock_init_base::startup(boost::asio::detail::winsock_init_base::data&, unsigned char, unsigned char)' 中:
D:/boost/boost_1_82_0/boost/asio/detail/impl/winsock_init.ipp:39: 未定义的引用 `__imp_WSAStartup'
D:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\MUHAMM~1\AppData\Local\Temp\cc44Ri3w.o: 在函数中 `boost::asio::detail::winsock_init_base::cleanup(boost::asio::detail::winsock_init_base::data&)' 中:
D:/boost/boost_1_82_0/boost/asio/detail/impl/winsock_init.ipp:56: 未定义的引用 `__imp_WSACleanup'
D:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\MUHAMM~1\AppData\Local\Temp\cc44Ri3w.o: 在函数中 `boost::asio::detail::socket_ops::get_last_error(boost::system::error_code&, bool)' 中:
D:/boost/boost_1_82_0/boost/asio/detail/impl/socket_ops.ipp:87: 未定义的引用 `__imp_WSAGetLastError'
D:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\MUHAMM~1\AppData\Local\Temp\cc44Ri3w.o: 在函数中 `boost::asio::detail::socket_ops::select(int, fd_set*, fd_set*, fd_set*, timeval*, boost::system::error_code&)' 中:
D:/boost/boost_1_82_0/boost/asio/detail/impl/socket_ops.ipp:2202: 未定义的引用 `__imp_select'
collect2.exe: 错误:ld 返回 1 退出状态

构建完成,带有错误。

我尝试了一些简单的事情,比如尝试包括<boost/system.hpp>,但那没有起作用。这是一个应该能够立即运行的简单默认应用程序。

英文:

So i am trying to compile the absolute basic ASIO tutorial code as given here

I am using MINGW 64 for compiling.
However i am getting a bunch of linker errors in the terminal :

Starting build...
D:\mingw64\bin\g++.exe -fdiagnostics-color=always -g -I D:\boost\boost_1_82_0
&quot;D:\Development\simplefolder\simpleclient.cpp&quot; -o &quot;D:\Development\surviving mars\simplefolder\simpleclient.exe&quot;
D:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\MUHAMM~1\AppData\Local\Temp\cc44Ri3w.o: in function `boost::asio::detail::winsock_init_base::startup(boost::asio::detail::winsock_init_base::data&amp;, unsigned char, unsigned char)&#39;:
D:/boost/boost_1_82_0/boost/asio/detail/impl/winsock_init.ipp:39: undefined reference to `__imp_WSAStartup&#39;
D:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\MUHAMM~1\AppData\Local\Temp\cc44Ri3w.o: in function `boost::asio::detail::winsock_init_base::cleanup(boost::asio::detail::winsock_init_base::data&amp;)&#39;:
D:/boost/boost_1_82_0/boost/asio/detail/impl/winsock_init.ipp:56: undefined reference to `__imp_WSACleanup&#39;
D:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\MUHAMM~1\AppData\Local\Temp\cc44Ri3w.o: in function `boost::asio::detail::socket_ops::get_last_error(boost::system::error_code&amp;, bool)&#39;:
D:/boost/boost_1_82_0/boost/asio/detail/impl/socket_ops.ipp:87: undefined reference to `__imp_WSAGetLastError&#39;
D:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\MUHAMM~1\AppData\Local\Temp\cc44Ri3w.o: in function `boost::asio::detail::socket_ops::select(int, fd_set*, fd_set*, fd_set*, timeval*, boost::system::error_code&amp;)&#39;:
D:/boost/boost_1_82_0/boost/asio/detail/impl/socket_ops.ipp:2202: undefined reference to `__imp_select&#39;
collect2.exe: error: ld returned 1 exit status

Build finished with error(s).

I tried various simple things like trying to include <boost/system.hpp> But that didn't work. This is a simple default application which should work out of the box

答案1

得分: 2

已找到解决方案
在参数中添加3个额外的库,如下所示:

D:\mingw64\bin\g++.exe -fdiagnostics-color=always -g -I D:\boost\boost_1_82_0 "D:\Development\simplefolder\simpleclient.cpp" -l gdi32 -l wsock32 -l ws2_32 -o "D:\Development\simplefolder\simpleclient.exe"

添加了3个额外的库:-l gdi32 -l wsock32 -l ws2_32
问题已解决

英文:

Found the solution to be
In the arguments add 3 extra libraries as follows:

D:\mingw64\bin\g++.exe -fdiagnostics-color=always -g -I D:\boost\boost_1_82_0 &quot;D:\Development\simplefolder\simpleclient.cpp&quot; **-l gdi32 -l wsock32 -l ws2_32** -o &quot;D:\Development\simplefolder\simpleclient.exe&quot;

Adding 3 Additional Libraries: -l gdi32 -l wsock32 -l ws2_32
solved it

huangapple
  • 本文由 发表于 2023年6月13日 08:17:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/76460984.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定