英文:
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
"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: in function `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: undefined reference to `__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: in function `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: undefined reference to `__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: in function `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: undefined reference to `__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: in function `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: undefined reference to `__imp_select'
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 "D:\Development\simplefolder\simpleclient.cpp" **-l gdi32 -l wsock32 -l ws2_32** -o "D:\Development\simplefolder\simpleclient.exe"
Adding 3 Additional Libraries: -l gdi32 -l wsock32 -l ws2_32
solved it
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论