This question already has answers here:
redefinition errors in WinSock2.h [duplicate]
                                
                                    (2个答案)
                                
                        
                                5年前关闭。
            
                    
Error   33  error C2375: 'accept' : redefinition; different linkage C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\winsock2.h  1578
Error   34  error C2375: 'bind' : redefinition; different linkage   C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\winsock2.h  1600
Error   35  error C2375: 'closesocket' : redefinition; different linkage    C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\winsock2.h  1619
Error   36  error C2375: 'connect' : redefinition; different linkage    C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\winsock2.h  1638
Error   37  error C2375: 'ioctlsocket' : redefinition; different linkage    C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\winsock2.h  1659
Error   38  error C2375: 'getpeername' : redefinition; different linkage    C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\winsock2.h  1680
Error   39  error C2375: 'getsockname' : redefinition; different linkage    C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\winsock2.h  1701
Error   40  error C2375: 'getsockopt' : redefinition; different linkage C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\winsock2.h  1724
Error   41  error C2375: 'htonl' : redefinition; different linkage  C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\winsock2.h  1745
Error   42  error C2375: 'htons' : redefinition; different linkage  C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\winsock2.h  1762
Error   43  error C2375: 'inet_addr' : redefinition; different linkage  C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\winsock2.h  1780
Error   44  error C2375: 'inet_ntoa' : redefinition; different linkage  C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\winsock2.h  1797
Error   45  error C2375: 'listen' : redefinition; different linkage C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\winsock2.h  1815


这些是我在准备项目构建时遇到的错误。我从搜索中发现,这可能是由于在包含winsock2之前包含了windows.h。
但是我还没有直接包含任何这些文件。在此先感谢您的帮助。

最佳答案

由于windows.h包含winsock.h(较早版本的winsock2.h),因此必须在行之前放置所有包含winsock2.h(或任何包含winsock2.h的文件,在本例中为zmq.h):

#include <windows.h>


正确的顺序是这样的:

.
.
#include "zmq.h"
.
.
#include <windows.h>

关于c++ - Visual Studio 2010 C++中的构建错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25989436/

10-10 16:11