2010-01-09 114 views
37

我在Windows上使用MinGW编译器来编译带有套接字的C++应用程序。我的链接看起来像命令:MinGW链接器错误:winsock

g++.exe -Wall -Wno-long-long -pedantic -lwsock32 -o dist/Windows/piskvorky { there are a lot of object files } 

,我也试过

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 `[email protected]' 
build/Windows/MinGW-Windows/src/utils/tcpunit.o:tcpunit.cpp:(.text+0xd0): undefined reference to `[email protected]' 
build/Windows/MinGW-Windows/src/utils/tcpunit.o:tcpunit.cpp:(.text+0x1ee): undefined reference to `[email protected]' 
build/Windows/MinGW-Windows/src/utils/tcpdevice.o:tcpdevice.cpp:(.text+0x184): undefined reference to `[email protected]' 
build/Windows/MinGW-Windows/src/utils/tcpdevice.o:tcpdevice.cpp:(.text+0x1a5): undefined reference to `[email protected]' 
build/Windows/MinGW-Windows/src/utils/tcpdevice.o:tcpdevice.cpp:(.text+0x1cb): undefined reference to `[email protected]' 
build/Windows/MinGW-Windows/src/utils/tcpdevice.o:tcpdevice.cpp:(.text+0x1d3): undefined reference to `[email protected]' 
build/Windows/MinGW-Windows/src/utils/tcpdevice.o:tcpdevice.cpp:(.text+0x6fe): undefined reference to `[email protected]' 
build/Windows/MinGW-Windows/src/utils/tcpdevice.o:tcpdevice.cpp:(.text+0x724): undefined reference to `[email protected]' 
build/Windows/MinGW-Windows/src/utils/tcpdevice.o:tcpdevice.cpp:(.text+0x7f0): undefined reference to `[email protected]' 
build/Windows/MinGW-Windows/src/utils/tcpdevice.o:tcpdevice.cpp:(.text+0x83c): undefined reference to `[email protected]' 
build/Windows/MinGW-Windows/src/utils/tcpdevice.o:tcpdevice.cpp:(.text+0x86f): undefined reference to `[email protected]' 
build/Windows/MinGW-Windows/src/utils/tcpdevice.o:tcpdevice.cpp:(.text+0x8b5): undefined reference to `[email protected]' 
build/Windows/MinGW-Windows/src/utils/tcpdevice.o:tcpdevice.cpp:(.text+0x9c6): undefined reference to `[email protected]' 

你有任何想法哪里出了问题可以吗?

+0

piškvorkyse socketama? :D – 2013-03-19 18:32:48

+0

@Matous是的,游戏有一个网络模式 – Gaim 2013-03-20 08:21:15

回答

98

-lws2_32放到目标文件列表的后面 - GCC按照它们在命令行上出现的顺序搜索库和目标文件。

只是为了帮助其他观众那里:

gcc hello.c -o hello.o -lws2_32 
+4

非常感谢您的建议 – Gaim 2010-01-09 14:30:36

+0

工程..谢谢队友 – 2015-07-26 02:54:26

-2

问候我只是通过上面的问题就走....

因此,这里有一些意见第一关....

我知道你是指MinGw,但你可能需要cygwin来解决这个问题,我不知道mingw那么好,我更了解cygwin。但我知道他们是彼此的表亲。

Cygwin附带预编译的boost库,但谁知道它们是哪个版本。我相信可以检查,但是谁有时间这样做?我不链接到cygwin boost库或mingw boost库,我使用gcc在Windows(cygwin)上从头创建了boost。编译没有问题。

在写这篇文章的时候,版本1.47.0提升了我的信心。

事实上,cygwin使用版本(x?)和boost为1.47.0可能是一个主要问题。让你知道你在用什么方式提升。

我使用的是在boost 1.42上开发的代码,并且有相关的链接器错误。代码编译,头文件被找到,etc ..等等...但后来我得到了未定义的引用WSA等... etcocketets这个,关闭插座,等......

所以,显然,为了实现网络套接字,需要一个平台库,其中以windows的ws2_32格式和Linux的套接字格式存在。

因此,如果您正确使用boost,并且包含正确的boost系统库,则可能还需要特定于操作系统的库来访问某些资源(本例中为联网)。

之后链接器错误消失。这可能是显而易见的提高退伍军人这里发生了什么,但我无法通过谷歌找到明确的答案。

5

与月食上的mingw: 菜单 - 项目 - 属性 - c/C++构建 - 设置:注册“工具设置” - MinGW C链接器 - 其他:下部“其他对象”add:“D:\ Programmierung \ mingw \ lib \ libwsock32.a“为例。对于任何其他需要的属性,没有其他libwsock32.a条目,特别是不在Library-entries中。也没有关于这个Lib的标志。

+0

请用英语发表所有答案。 – 2015-05-04 22:02:17

+1

答案是英文...路径不是,但这不应该是一个问题。 – jazzpi 2016-09-18 21:53:08

+0

此答案适用。 – 2016-12-15 02:58:15

1

在:

菜单 - 项目 - 属性 - C/C++编译 - 设置:注册 “工具设置” - MinGW的C++链接器 - 其他:降低部分 “其他对象”

地址:libwsock32.a bin文件夹中的MinGW