在 Windows 10 上使用 CZMQ 编译 dll 时出错

Posted

技术标签:

【中文标题】在 Windows 10 上使用 CZMQ 编译 dll 时出错【英文标题】:Errors compiling dll using CZMQ on Windows 10 【发布时间】:2018-01-13 15:44:06 【问题描述】:

我在 Windows 10 上使用 Visual Studio 2015 编译具有套接字网络功能的 .dll。来自CZMQ 的dll #includes <czmq.h>。当我尝试编译时,有很多与“未找到标识符”和“重新定义”Windows 网络元素有关的错误。我尝试了各种添加:

#define WIN32_LEAN_AND_MEAN

#define WINSOCK_API_LINKAGE

#define _WINSOCK2API_ // stops windows.h including winsock.h

#define _WINSOCKAPI_

单独和组合到我的源代码。仅#define WINSOCK_API_LINKAGE 就大大减少了错误的数量,但并没有全部清除。任何人都知道问题是什么以及如何纠正错误并让.dll 编译?

谢谢

注意事项:

在同一台计算机上使用相同的开发环境.exe 文件在源代码中有#include <czmq.h> 时编译得很好,.dll 文件是另一回事;所有错误。

当使用来自zeromq 的#include <zmq.h> 构建.dll 文件时,必须指定#define _WINSOCK2API_ 以清除类似错误并在Windows 上成功编译。在这些情况下,源中不存在CZMQ

.dllCZMQ 编译的错误:

1>------ Build started: Project: TS_Origin, Configuration: Release Win32     ------
1>  SD_Source.cpp
1>C:\Program Files (x86)\Windows Kits\8.1\Include\shared\ws2def.h(100): warning C4005: 'AF_IPX' : macro redefinition
1>          C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock.h(452) : see previous definition of 'AF_IPX'
1>C:\Program Files (x86)\Windows Kits\8.1\Include\shared\ws2def.h(140): warning C4005: 'AF_MAX' : macro redefinition
1>          C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock.h(471) : see previous definition of 'AF_MAX'
1>C:\Program Files (x86)\Windows Kits\8.1\Include\shared\ws2def.h(177): warning C4005: 'SO_DONTLINGER' : macro redefinition
1>          C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock.h(394) : see previous definition of 'SO_DONTLINGER'
1>C:\Program Files (x86)\Windows Kits\8.1\Include\shared\ws2def.h(221): error C2011: 'sockaddr' : 'struct' type redefinition
1>          C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock.h(477) : see declaration of 'sockaddr'
1>C:\Program Files (x86)\Windows Kits\8.1\Include\shared\ws2def.h(421): error C2059: syntax error : 'constant'
1>C:\Program Files (x86)\Windows Kits\8.1\Include\shared\ws2def.h(421): error C3805: 'constant': unexpected token, expected either '' or a ','
1>C:\Program Files (x86)\Windows Kits\8.1\Include\shared\ws2def.h(556): warning C4005: 'IN_CLASSA' : macro redefinition
1>          C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock.h(279) : see previous definition of 'IN_CLASSA'
1>C:\Program Files (x86)\Windows Kits\8.1\Include\shared\ws2def.h(562): warning C4005: 'IN_CLASSB' : macro redefinition
1>          C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock.h(285) : see previous definition of 'IN_CLASSB'
1>C:\Program Files (x86)\Windows Kits\8.1\Include\shared\ws2def.h(568): warning C4005: 'IN_CLASSC' : macro redefinition
1>          C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock.h(291) : see previous definition of 'IN_CLASSC'
1>C:\Program Files (x86)\Windows Kits\8.1\Include\shared\ws2def.h(579): warning C4005: 'INADDR_ANY' : macro redefinition
1>          C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock.h(296) : see previous definition of 'INADDR_ANY'
1>C:\Program Files (x86)\Windows Kits\8.1\Include\shared\ws2def.h(581): warning C4005: 'INADDR_BROADCAST' : macro redefinition
1>          C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock.h(298) : see previous definition of 'INADDR_BROADCAST'
1>C:\Program Files (x86)\Windows Kits\8.1\Include\shared\ws2def.h(615): error C2011: 'sockaddr_in' : 'struct' type redefinition
1>          C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock.h(304) : see declaration of 'sockaddr_in'
1>C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock2.h(136): error C2011: 'fd_set' : 'struct' type redefinition
1>          C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock.h(60) : see declaration of 'fd_set'
1>C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock2.h(156): warning C4005: 'FD_CLR' : macro redefinition
1>          C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock.h(89) : see previous definition of 'FD_CLR'
1>C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock2.h(171): warning C4005: 'FD_SET' : macro redefinition
1>          C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock.h(94) : see previous definition of 'FD_SET'
1>C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock2.h(180): error C2011: 'timeval' : 'struct' type redefinition
1>          C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock.h(103) : see declaration of 'timeval'
1>C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock2.h(236): error C2011: 'hostent' : 'struct' type redefinition
1>          C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock.h(159) : see declaration of 'hostent'
1>C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock2.h(249): error C2011: 'netent' : 'struct' type redefinition
1>          C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock.h(172) : see declaration of 'netent'
1>C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock2.h(256): error C2011: 'servent' : 'struct' type redefinition
1>          C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock.h(179) : see declaration of 'servent'
1>C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock2.h(268): error C2011: 'protoent' : 'struct' type redefinition
1>          C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock.h(191) : see declaration of 'protoent'
1>C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock2.h(364): error C2011: 'WSAData' : 'struct' type redefinition
1>          C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock.h(314) : see declaration of 'WSAData'
1>C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock2.h(462): error C2011: 'sockproto' : 'struct' type redefinition
1>          C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock.h(486) : see declaration of 'sockproto'
1>C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock2.h(504): error C2011: 'linger' : 'struct' type redefinition
1>          C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock.h(523) : see declaration of 'linger'
1>C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock2.h(517): warning C4005: 'SOMAXCONN' : macro redefinition
1>          C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock.h(536) : see previous definition of 'SOMAXCONN'
1>C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock2.h(551): warning C4005: 'FD_READ' : macro redefinition
1>          C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock.h(554) : see previous definition of 'FD_READ'
1>C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock2.h(554): warning C4005: 'FD_WRITE' : macro redefinition
1>          C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock.h(555) : see previous definition of 'FD_WRITE'
1>C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock2.h(557): warning C4005: 'FD_OOB' : macro redefinition
1>          C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock.h(556) : see previous definition of 'FD_OOB'
1>C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock2.h(560): warning C4005: 'FD_ACCEPT' : macro redefinition
1>          C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock.h(557) : see previous definition of 'FD_ACCEPT'
1>C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock2.h(563): warning C4005: 'FD_CONNECT' : macro redefinition
1>          C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock.h(558) : see previous definition of 'FD_CONNECT'
1>C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock2.h(566): warning C4005: 'FD_CLOSE' : macro redefinition
1>          C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock.h(559) : see previous definition of 'FD_CLOSE'
1>C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock2.h(1650): error C2375: 'accept' : redefinition; different linkage
1>          C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock.h(734) : see declaration of 'accept'
1>C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock2.h(1672): error C2375: 'bind' : redefinition; different linkage
1>          C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock.h(739) : see declaration of 'bind'
1>C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock2.h(1691): error C2375: 'closesocket' : redefinition; different linkage
1>          C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock.h(744) : see declaration of 'closesocket'
1>C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock2.h(1710): error C2375: 'connect' : redefinition; different linkage
1>          C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock.h(746) : see declaration of 'connect'
1>C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock2.h(1731): error C2375: 'ioctlsocket' : redefinition; different linkage
1>          C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock.h(751) : see declaration of 'ioctlsocket'
1>C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock2.h(1752): error C2375: 'getpeername' : redefinition; different linkage
1>          C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock.h(756) : see declaration of 'getpeername'
1>C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock2.h(1773): error C2375: 'getsockname' : redefinition; different linkage
1>          C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock.h(761) : see declaration of 'getsockname'
1>C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock2.h(1796): error C2375: 'getsockopt' : redefinition; different linkage
1>          C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock.h(766) : see declaration of 'getsockopt'
1>C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock2.h(1817): error C2375: 'htonl' : redefinition; different linkage
1>          C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock.h(773) : see declaration of 'htonl'
1>C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock2.h(1834): error C2375: 'htons' : redefinition; different linkage
1>          C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock.h(775) : see declaration of 'htons'
1>C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock2.h(1852): error C2375: 'inet_addr' : redefinition; different linkage
1>          C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock.h(777) : see declaration of 'inet_addr'
1>C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock2.h(1870): error C2375: 'inet_ntoa' : redefinition; different linkage
1>          C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock.h(779) : see declaration of 'inet_ntoa'
1>C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock2.h(1971): error C2375: 'listen' : redefinition; different linkage
1>          C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock.h(781) : see declaration of 'listen'
1>C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock2.h(1989): error C2375: 'ntohl' : redefinition; different linkage
1>          C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock.h(785) : see declaration of 'ntohl'
1>C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock2.h(2006): error C2375: 'ntohs' : redefinition; different linkage
1>          C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock.h(787) : see declaration of 'ntohs'
1>C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock2.h(2026): error C2375: 'recv' : redefinition; different linkage
1>          C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock.h(789) : see declaration of 'recv'
1>C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock2.h(2051): error C2375: 'recvfrom' : redefinition; different linkage
1>          C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock.h(795) : see declaration of 'recvfrom'
1>C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock2.h(2077): error C2375: 'select' : redefinition; different linkage
1>          C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock.h(803) : see declaration of 'select'
1>C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock2.h(2101): error C2375: 'send' : redefinition; different linkage
1>          C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock.h(810) : see declaration of 'send'
1>C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock2.h(2126): error C2375: 'sendto' : redefinition; different linkage
1>          C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock.h(816) : see declaration of 'sendto'
1>C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock2.h(2152): error C2375: 'setsockopt' : redefinition; different linkage
1>          C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock.h(824) : see declaration of 'setsockopt'
1>C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock2.h(2174): error C2375: 'shutdown' : redefinition; different linkage
1>          C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock.h(831) : see declaration of 'shutdown'
1>C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock2.h(2195): error C2375: 'socket' : redefinition; different linkage
1>          C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock.h(835) : see declaration of 'socket'
1>C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock2.h(2220): error C2375: 'gethostbyaddr' : redefinition; different linkage
1>          C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock.h(842) : see declaration of 'gethostbyaddr'
1>C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock2.h(2240): error C2375: 'gethostbyname' : redefinition; different linkage
1>          C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock.h(847) : see declaration of 'gethostbyname'
1>C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock2.h(2258): error C2375: 'gethostname' : redefinition; different linkage
1>          C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock.h(849) : see declaration of 'gethostname'
1>C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock2.h(2298): error C2375: 'getservbyport' : redefinition; different linkage
1>          C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock.h(853) : see declaration of 'getservbyport'
1>C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock2.h(2317): error C2375: 'getservbyname' : redefinition; different linkage
1>          C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock.h(857) : see declaration of 'getservbyname'
1>C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock2.h(2335): error C2375: 'getprotobynumber' : redefinition; different linkage
1>          C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock.h(861) : see declaration of 'getprotobynumber'
1>C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock2.h(2352): error C2375: 'getprotobyname' : redefinition; different linkage
1>          C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock.h(863) : see declaration of 'getprotobyname'
1>C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock2.h(2373): error C2375: 'WSAStartup' : redefinition; different linkage
1>          C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock.h(867) : see declaration of 'WSAStartup'
1>C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock2.h(2392): error C2375: 'WSACleanup' : redefinition; different linkage
1>          C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock.h(871) : see declaration of 'WSACleanup'
1>C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock2.h(2409): error C2375: 'WSASetLastError' : redefinition; different linkage
1>          C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock.h(873) : see declaration of 'WSASetLastError'
1>C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock2.h(2426): error C2375: 'WSAGetLastError' : redefinition; different linkage
1>          C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock.h(875) : see declaration of 'WSAGetLastError'
1>C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock2.h(2447): error C2375: 'WSAIsBlocking' : redefinition; different linkage
1>          C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock.h(877) : see declaration of 'WSAIsBlocking'
1>C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock2.h(2465): error C2375: 'WSAUnhookBlockingHook' : redefinition; different linkage
1>          C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock.h(879) : see declaration of 'WSAUnhookBlockingHook'
1>C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock2.h(2483): error C2375: 'WSASetBlockingHook' : redefinition; different linkage
1>          C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock.h(881) : see declaration of 'WSASetBlockingHook'
1>C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock2.h(2501): error C2375: 'WSACancelBlockingCall' : redefinition; different linkage
1>          C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock.h(883) : see declaration of 'WSACancelBlockingCall'
1>C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock2.h(2524): error C2375: 'WSAAsyncGetServByName' : redefinition; different linkage
1>          C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock.h(885) : see declaration of 'WSAAsyncGetServByName'
1>C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock2.h(2552): error C2375: 'WSAAsyncGetServByPort' : redefinition; different linkage
1>          C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock.h(893) : see declaration of 'WSAAsyncGetServByPort'
1>C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock2.h(2579): error C2375: 'WSAAsyncGetProtoByName' : redefinition; different linkage
1>          C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock.h(901) : see declaration of 'WSAAsyncGetProtoByName'
1>C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock2.h(2605): error C2375: 'WSAAsyncGetProtoByNumber' : redefinition; different linkage
1>          C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock.h(908) : see declaration of 'WSAAsyncGetProtoByNumber'
1>C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock2.h(2631): error C2375: 'WSAAsyncGetHostByName' : redefinition; different linkage
1>          C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock.h(915) : see declaration of 'WSAAsyncGetHostByName'
1>C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock2.h(2659): error C2375: 'WSAAsyncGetHostByAddr' : redefinition; different linkage
1>          C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock.h(922) : see declaration of 'WSAAsyncGetHostByAddr'
1>C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock2.h(2683): error C2375: 'WSACancelAsyncRequest' : redefinition; different linkage
1>          C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock.h(931) : see declaration of 'WSACancelAsyncRequest'
1>C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock2.h(2704): error C2375: 'WSAAsyncSelect' : redefinition; different linkage
1>          C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock.h(933) : see declaration of 'WSAAsyncSelect'
1>C:\Program Files (x86)\Windows Kits\8.1\Include\shared\ws2ipdef.h(76): error C2079: 'sockaddr_gen::Address' uses undefined struct 'sockaddr'
1>C:\Program Files (x86)\Windows Kits\8.1\Include\shared\ws2ipdef.h(77): error C2079: 'sockaddr_gen::AddressIn' uses undefined struct 'sockaddr_in'
1>C:\Program Files (x86)\Windows Kits\8.1\Include\shared\ws2ipdef.h(120): warning C4005: 'IP_TOS' : macro redefinition
1>          C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock.h(344) : see previous definition of 'IP_TOS'
1>C:\Program Files (x86)\Windows Kits\8.1\Include\shared\ws2ipdef.h(121): warning C4005: 'IP_TTL' : macro redefinition
1>          C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock.h(343) : see previous definition of 'IP_TTL'
1>C:\Program Files (x86)\Windows Kits\8.1\Include\shared\ws2ipdef.h(122): warning C4005: 'IP_MULTICAST_IF' : macro redefinition
1>          C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock.h(338) : see previous definition of 'IP_MULTICAST_IF'
1>C:\Program Files (x86)\Windows Kits\8.1\Include\shared\ws2ipdef.h(123): warning C4005: 'IP_MULTICAST_TTL' : macro redefinition
1>          C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock.h(339) : see previous definition of 'IP_MULTICAST_TTL'
1>C:\Program Files (x86)\Windows Kits\8.1\Include\shared\ws2ipdef.h(124): warning C4005: 'IP_MULTICAST_LOOP' : macro redefinition
1>          C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock.h(340) : see previous definition of 'IP_MULTICAST_LOOP'
1>C:\Program Files (x86)\Windows Kits\8.1\Include\shared\ws2ipdef.h(125): warning C4005: 'IP_ADD_MEMBERSHIP' : macro redefinition
1>          C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock.h(341) : see previous definition of 'IP_ADD_MEMBERSHIP'
1>C:\Program Files (x86)\Windows Kits\8.1\Include\shared\ws2ipdef.h(126): warning C4005: 'IP_DROP_MEMBERSHIP' : macro redefinition
1>          C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock.h(342) : see previous definition of 'IP_DROP_MEMBERSHIP'
1>C:\Program Files (x86)\Windows Kits\8.1\Include\shared\ws2ipdef.h(127): warning C4005: 'IP_DONTFRAGMENT' : macro redefinition
1>          C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock.h(345) : see previous definition of 'IP_DONTFRAGMENT'
1>C:\Program Files (x86)\Windows Kits\8.1\Include\shared\ws2ipdef.h(202): error C2079: '_SOCKADDR_INET::Ipv4' uses undefined struct 'sockaddr_in'
1>C:\Program Files (x86)\Windows Kits\8.1\Include\shared\ws2ipdef.h(715): error C2011: 'ip_mreq' : 'struct' type redefinition
1>          C:\Program Files (x86)\Windows Kits\8.1\Include\um\winsock.h(355) : see declaration of 'ip_mreq'
1>C:\Program Files (x86)\Windows Kits\8.1\Include\um\ws2tcpip.h(729): error C3861: 'WSASetLastError': identifier not found
1>C:\Program Files (x86)\Windows Kits\8.1\Include\um\ws2tcpip.h(736): error C3861: 'WSASetLastError': identifier not found
1>C:\Program Files (x86)\Windows Kits\8.1\Include\um\ws2tcpip.h(775): error C3861: 'WSASetLastError': identifier not found
1>C:\Program Files (x86)\Windows Kits\8.1\Include\um\ws2tcpip.h(782): error C3861: 'WSASetLastError': identifier not found
1>C:\Program Files (x86)\Windows Kits\8.1\Include\um\ws2tcpip.h(826): error C3861: 'WSASetLastError': identifier not found
1>C:\Program Files (x86)\Windows Kits\8.1\Include\um\ws2tcpip.h(833): error C3861: 'WSASetLastError': identifier not found
1>C:\Program Files (x86)\Windows Kits\8.1\Include\um\ws2tcpip.h(874): error C3861: 'WSASetLastError': identifier not found
1>C:\Program Files (x86)\Windows Kits\8.1\Include\um\ws2tcpip.h(881): error C3861: 'WSASetLastError': identifier not found
1>c:\users\stephen\czmq\include\czmq_prelude.h(413): error C2079: '<unnamed-tag>::__addr' uses undefined struct 'sockaddr_in'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

【问题讨论】:

【参考方案1】:

如果宏实际上是相同的,请使用#pragma warning(disable, ) 来打开它

particular warning off, you might want to wrap the include in:
#pragma warning(push)
#pragma warning(disable, 40050
#include<czmq.h>
#pragma warning(pop)

这将在解析标头时禁用警告,但在其他情况下启用它。

对于未定义的结构错误,我建议您在 windows.h 之前 #include .h 首先)。

【讨论】:

CZMQ 正在引入 winsock2.h 和 windows.h。我没有在我的来源中提及它们。 github.com/zeromq/czmq/blob/master/include/czmq_prelude.h#L251【参考方案2】:

好的,所以回答我自己的问题。我的源代码使用#import "path\to\folder\other.dll"。这个专有的 other.dll 显然是在牵扯 Windows 功能的某些方面,从而导致重复。答案是第一;

#include <czmq.h>

紧随其后

#import "path\to\folder\other.dll"

然后错误消失了,.dll 遵守了。唷。

【讨论】:

以上是关于在 Windows 10 上使用 CZMQ 编译 dll 时出错的主要内容,如果未能解决你的问题,请参考以下文章

如何在Windows 10上使用VS2019 编译C

如何在Windows 10上使用VS2019 编译C

如何在Windows 7上改进Qt + MSVC编译时间?

MPI 在Windows10 上安装,使用VS2013编译生成可执行程序

MPI 在Windows10 上安装,使用VS2013编译生成可执行程序

使用Golang 1.10编译Windows DLL时遇到问题。