MinGW链接器错误:winsock < >我在Windows上使用MinGW编译器来编译带有套接字的C++应用程序。我的链接命令如下所示: g++.exe -Wall -Wno-long-long -pedantic -lwsock32 -o dist/Windows/piskvorky { there are a lot of object files }

MinGW链接器错误:winsock < >我在Windows上使用MinGW编译器来编译带有套接字的C++应用程序。我的链接命令如下所示: g++.exe -Wall -Wno-long-long -pedantic -lwsock32 -o dist/Windows/piskvorky { there are a lot of object files },c++,linker,mingw,winsock,C++,Linker,Mingw,Winsock,我也试过了 g++.exe -Wall -Wno-long-long -pedantic -lws2_32 -o dist/Windows/piskvorky { there are a lot of object files } 但在这两种情况下,我都会出现以下错误: build/Windows/MinGW-Windows/src/utils/tcpunit.o:tcpunit.cpp:(.text+0x33): undefined reference to `closesocket@4'

我也试过了

g++.exe -Wall -Wno-long-long -pedantic -lws2_32 -o dist/Windows/piskvorky { there are a lot of object files }
但在这两种情况下,我都会出现以下错误:

build/Windows/MinGW-Windows/src/utils/tcpunit.o:tcpunit.cpp:(.text+0x33): undefined reference to `closesocket@4'
build/Windows/MinGW-Windows/src/utils/tcpunit.o:tcpunit.cpp:(.text+0xd0): undefined reference to `send@16'
build/Windows/MinGW-Windows/src/utils/tcpunit.o:tcpunit.cpp:(.text+0x1ee): undefined reference to `recv@16'
build/Windows/MinGW-Windows/src/utils/tcpdevice.o:tcpdevice.cpp:(.text+0x184): undefined reference to `WSAStartup@8'
build/Windows/MinGW-Windows/src/utils/tcpdevice.o:tcpdevice.cpp:(.text+0x1a5): undefined reference to `closesocket@4'
build/Windows/MinGW-Windows/src/utils/tcpdevice.o:tcpdevice.cpp:(.text+0x1cb): undefined reference to `closesocket@4'
build/Windows/MinGW-Windows/src/utils/tcpdevice.o:tcpdevice.cpp:(.text+0x1d3): undefined reference to `WSACleanup@0'
build/Windows/MinGW-Windows/src/utils/tcpdevice.o:tcpdevice.cpp:(.text+0x6fe): undefined reference to `bind@12'
build/Windows/MinGW-Windows/src/utils/tcpdevice.o:tcpdevice.cpp:(.text+0x724): undefined reference to `listen@8'
build/Windows/MinGW-Windows/src/utils/tcpdevice.o:tcpdevice.cpp:(.text+0x7f0): undefined reference to `gethostbyaddr@12'
build/Windows/MinGW-Windows/src/utils/tcpdevice.o:tcpdevice.cpp:(.text+0x83c): undefined reference to `socket@12'
build/Windows/MinGW-Windows/src/utils/tcpdevice.o:tcpdevice.cpp:(.text+0x86f): undefined reference to `htons@4'
build/Windows/MinGW-Windows/src/utils/tcpdevice.o:tcpdevice.cpp:(.text+0x8b5): undefined reference to `connect@12'
build/Windows/MinGW-Windows/src/utils/tcpdevice.o:tcpdevice.cpp:(.text+0x9c6): undefined reference to `accept@12'

您知道问题可能出在哪里吗?

-lws2\u 32
放在目标文件列表之后-GCC按命令行上出现的顺序搜索库和目标文件

为了帮助其他观众:

gcc hello.c -o hello.o -lws2_32

您好,我刚刚解决了上面的问题

首先,这里是一些观察结果

我知道你指的是明哥,但你可能需要赛文来解决这个问题,我不太了解明哥,我更了解赛文。但我知道他们是表亲

Cygwin附带了预编译的boost库,但谁知道它们是哪个版本呢。我相信这是可以检查的,但谁有时间去做呢?我没有链接cygwin boost库或mingw boost库,我是在windows上使用gcc(cygwin)从头构建boost的。编译做得很好

在撰写本文时,我相信boost是1.47.0版的

cygwin使用版本(x?)和boost is 1.47.0这一事实可能是一个主要问题。让你知道你用的是什么方式来推动

我使用的代码是在Boost1.42上开发的,并且有相关的链接器错误。编译的代码、找到的头等等。。。但后来我得到了WSA的未定义引用,等等…打开套接字这个,关闭套接字那个,等等

因此,显然,为了实现网络套接字,boost需要一个平台库,其中以ws2_32 for windows和socket for linux的形式存在

因此,如果您正确地使用了boost,并且包含了正确的boost系统库,那么您可能还需要一个特定于操作系统的库来访问一些资源(在本例中是联网)

链接器错误出现在这之后。很明显,这对老兵们来说是件好事,但我无法通过谷歌找到一个明确的答案。

在eclipse上使用mingw: Menu-Projekt-Properties-c/c++Build-Settings:Register“Tool Settings”-MinGW c Linker-杂项:下半部分“other objects”添加:“D:\Programmierung\MinGW\lib\libwsock32.a”例如。libwsock32.a不需要任何其他属性上的其他条目,尤其是库条目中的条目。也没有与此库相关的标志。

在:

菜单- Projtual-属性-C/C++构建-设置:登记“工具设置”-MIWC++链接器:杂项:下层“其他对象”< /P>


添加:libwsock32.a来自MinGW的bin文件夹D@Matous是的,游戏有一个网络模式答案是英语。。。路径不是,但这不应该是一个问题。