为啥我可以在EXE上编译DLL却不能编译
Posted
技术标签:
【中文标题】为啥我可以在EXE上编译DLL却不能编译【英文标题】:Why can I not compile DLL when I can do on EXE为什么我可以在EXE上编译DLL却不能编译 【发布时间】:2019-12-12 08:30:35 【问题描述】:我正在尝试将 http 服务器实现到 dll 中
我编译静态版Goahead(https://www.embedthis.com/goahead/)
我使用控制台 exe 创建了示例应用程序,并确认它可以按预期工作
但是,当我使用 DLL 制作相同的示例应用程序时,VS2019 中出现大量错误并拒绝编译
我什至无法将任何代码合并到 DLL 中
一旦我包含这个静态库,我就无法编译 DLL 并出现以下错误
我是否需要一些额外的设置才能使其在 DLL 上工作?
// dllmain.cpp : Defines the entry point for the DLL application.
#include <Windows.h>
#include "dllmain.h"
BOOL APIENTRY DllMain( HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved )
switch (ul_reason_for_call)
case DLL_PROCESS_ATTACH:
MessageBox(0, L"Hello From dll!", L"Hello", MB_ICONINFORMATION);
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
return TRUE;
//dllmain.h
#pragma once
#include "goahead/goahead.h"
#pragma comment(lib, "libgo.lib")
我什至尝试用 extern "C" 换行,但结果是一样的
//dllmain.h
#pragma once
extern "C"
#include "goahead/goahead.h"
#pragma comment(lib, "libgo.lib")
1>------ Build started: Project: httpd_dll, Configuration: Debug Win32 ------
1>dllmain.cpp
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\shared\ws2def.h(103,1): warning C4005: 'AF_IPX': macro redefinition
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock.h(457): message : see previous definition of 'AF_IPX'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\shared\ws2def.h(147,1): warning C4005: 'AF_MAX': macro redefinition
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock.h(476): message : see previous definition of 'AF_MAX'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\shared\ws2def.h(185,1): warning C4005: 'SO_DONTLINGER': macro redefinition
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock.h(399): message : see previous definition of 'SO_DONTLINGER'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\shared\ws2def.h(238,25): error C2011: 'sockaddr': 'struct' type redefinition
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock.h(1007): message : see declaration of 'sockaddr'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\shared\ws2def.h(440,5): error C2143: syntax error: missing '' before 'constant'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\shared\ws2def.h(440,27): error C2059: syntax error: 'constant'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\shared\ws2def.h(494,1): error C2143: syntax error: missing ';' before ''
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\shared\ws2def.h(494,10): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\shared\ws2def.h(494,20): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\shared\ws2def.h(575,1): warning C4005: 'IN_CLASSA': macro redefinition
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock.h(284): message : see previous definition of 'IN_CLASSA'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\shared\ws2def.h(581,1): warning C4005: 'IN_CLASSB': macro redefinition
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock.h(290): message : see previous definition of 'IN_CLASSB'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\shared\ws2def.h(587,1): warning C4005: 'IN_CLASSC': macro redefinition
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock.h(296): message : see previous definition of 'IN_CLASSC'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\shared\ws2def.h(598,1): warning C4005: 'INADDR_ANY': macro redefinition
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock.h(301): message : see previous definition of 'INADDR_ANY'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\shared\ws2def.h(600,1): warning C4005: 'INADDR_BROADCAST': macro redefinition
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock.h(303): message : see previous definition of 'INADDR_BROADCAST'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\shared\ws2def.h(636,28): error C2011: 'sockaddr_in': 'struct' type redefinition
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock.h(1011): message : see declaration of 'sockaddr_in'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock2.h(136,23): error C2011: 'fd_set': 'struct' type redefinition
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock.h(1019): message : see declaration of 'fd_set'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock2.h(156,1): warning C4005: 'FD_CLR': macro redefinition
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock.h(94): message : see previous definition of 'FD_CLR'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock2.h(171,1): warning C4005: 'FD_SET': macro redefinition
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock.h(99): message : see previous definition of 'FD_SET'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock2.h(180,16): error C2011: 'timeval': 'struct' type redefinition
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock.h(1035): message : see declaration of 'timeval'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock2.h(236,17): error C2011: 'hostent': 'struct' type redefinition
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock.h(1023): message : see declaration of 'hostent'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock2.h(249,16): error C2011: 'netent': 'struct' type redefinition
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock.h(177): message : see declaration of 'netent'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock2.h(256,17): error C2011: 'servent': 'struct' type redefinition
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock.h(1027): message : see declaration of 'servent'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock2.h(268,18): error C2011: 'protoent': 'struct' type redefinition
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock.h(1031): message : see declaration of 'protoent'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock2.h(364,24): error C2011: 'WSAData': 'struct' type redefinition
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock.h(319): message : see declaration of 'WSAData'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock2.h(462,18): error C2011: 'sockproto': 'struct' type redefinition
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock.h(491): message : see declaration of 'sockproto'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock2.h(504,16): error C2011: 'linger': 'struct' type redefinition
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock.h(1015): message : see declaration of 'linger'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock2.h(517,1): warning C4005: 'SOMAXCONN': macro redefinition
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock.h(541): message : see previous definition of 'SOMAXCONN'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock2.h(552,1): warning C4005: 'FD_READ': macro redefinition
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock.h(559): message : see previous definition of 'FD_READ'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock2.h(555,1): warning C4005: 'FD_WRITE': macro redefinition
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock.h(560): message : see previous definition of 'FD_WRITE'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock2.h(558,1): warning C4005: 'FD_OOB': macro redefinition
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock.h(561): message : see previous definition of 'FD_OOB'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock2.h(561,1): warning C4005: 'FD_ACCEPT': macro redefinition
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock.h(562): message : see previous definition of 'FD_ACCEPT'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock2.h(564,1): warning C4005: 'FD_CONNECT': macro redefinition
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock.h(563): message : see previous definition of 'FD_CONNECT'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock2.h(567,1): warning C4005: 'FD_CLOSE': macro redefinition
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock.h(564): message : see previous definition of 'FD_CLOSE'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock2.h(1625,1): error C2375: 'accept': redefinition; different linkage
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock.h(739): message : see declaration of 'accept'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock2.h(1647,1): error C2375: 'bind': redefinition; different linkage
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock.h(744): message : see declaration of 'bind'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock2.h(1668,1): error C2375: 'closesocket': redefinition; different linkage
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock.h(749): message : see declaration of 'closesocket'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock2.h(1685,1): error C2375: 'connect': redefinition; different linkage
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock.h(751): message : see declaration of 'connect'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock2.h(1706,1): error C2375: 'ioctlsocket': redefinition; different linkage
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock.h(756): message : see declaration of 'ioctlsocket'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock2.h(1729,1): error C2375: 'getpeername': redefinition; different linkage
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock.h(761): message : see declaration of 'getpeername'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock2.h(1750,1): error C2375: 'getsockname': redefinition; different linkage
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock.h(766): message : see declaration of 'getsockname'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock2.h(1771,1): error C2375: 'getsockopt': redefinition; different linkage
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock.h(771): message : see declaration of 'getsockopt'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock2.h(1796,1): error C2375: 'htonl': redefinition; different linkage
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock.h(778): message : see declaration of 'htonl'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock2.h(1813,1): error C2375: 'htons': redefinition; different linkage
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock.h(780): message : see declaration of 'htons'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock2.h(1831,1): error C2375: 'inet_addr': redefinition; different linkage
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock.h(782): message : see declaration of 'inet_addr'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock2.h(1849,1): error C2375: 'inet_ntoa': redefinition; different linkage
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock.h(784): message : see declaration of 'inet_ntoa'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock2.h(1949,1): error C2375: 'listen': redefinition; different linkage
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock.h(786): message : see declaration of 'listen'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock2.h(1968,1): error C2375: 'ntohl': redefinition; different linkage
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock.h(790): message : see declaration of 'ntohl'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock2.h(1985,1): error C2375: 'ntohs': redefinition; different linkage
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock.h(792): message : see declaration of 'ntohs'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock2.h(2002,1): error C2375: 'recv': redefinition; different linkage
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock.h(794): message : see declaration of 'recv'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock2.h(2025,1): error C2375: 'recvfrom': redefinition; different linkage
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock.h(800): message : see declaration of 'recvfrom'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock2.h(2052,1): error C2375: 'select': redefinition; different linkage
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock.h(808): message : see declaration of 'select'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock2.h(2077,1): error C2375: 'send': redefinition; different linkage
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock.h(815): message : see declaration of 'send'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock2.h(2100,1): error C2375: 'sendto': redefinition; different linkage
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock.h(821): message : see declaration of 'sendto'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock2.h(2127,1): error C2375: 'setsockopt': redefinition; different linkage
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock.h(829): message : see declaration of 'setsockopt'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock2.h(2152,1): error C2375: 'shutdown': redefinition; different linkage
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock.h(836): message : see declaration of 'shutdown'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock2.h(2172,1): error C2375: 'socket': redefinition; different linkage
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock.h(840): message : see declaration of 'socket'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock2.h(2197,1): error C2375: 'gethostbyaddr': redefinition; different linkage
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock.h(847): message : see declaration of 'gethostbyaddr'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock2.h(2219,1): error C2375: 'gethostbyname': redefinition; different linkage
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock.h(852): message : see declaration of 'gethostbyname'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock2.h(2236,1): error C2375: 'gethostname': redefinition; different linkage
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock.h(854): message : see declaration of 'gethostname'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock2.h(2276,1): error C2375: 'getservbyport': redefinition; different linkage
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock.h(858): message : see declaration of 'getservbyport'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock2.h(2295,1): error C2375: 'getservbyname': redefinition; different linkage
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock.h(862): message : see declaration of 'getservbyname'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock2.h(2314,1): error C2375: 'getprotobynumber': redefinition; different linkage
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock.h(866): message : see declaration of 'getprotobynumber'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock2.h(2331,1): error C2375: 'getprotobyname': redefinition; different linkage
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock.h(868): message : see declaration of 'getprotobyname'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock2.h(2351,1): error C2375: 'WSAStartup': redefinition; different linkage
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock.h(872): message : see declaration of 'WSAStartup'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock2.h(2371,1): error C2375: 'WSACleanup': redefinition; different linkage
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock.h(876): message : see declaration of 'WSACleanup'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock2.h(2388,1): error C2375: 'WSASetLastError': redefinition; different linkage
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock.h(878): message : see declaration of 'WSASetLastError'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock2.h(2405,1): error C2375: 'WSAGetLastError': redefinition; different linkage
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock.h(880): message : see declaration of 'WSAGetLastError'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock2.h(2426,1): error C2375: 'WSAIsBlocking': redefinition; different linkage
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock.h(882): message : see declaration of 'WSAIsBlocking'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock2.h(2444,1): error C2375: 'WSAUnhookBlockingHook': redefinition; different linkage
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock.h(884): message : see declaration of 'WSAUnhookBlockingHook'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock2.h(2462,1): error C2375: 'WSASetBlockingHook': redefinition; different linkage
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock.h(886): message : see declaration of 'WSASetBlockingHook'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock2.h(2480,1): error C2375: 'WSACancelBlockingCall': redefinition; different linkage
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock.h(888): message : see declaration of 'WSACancelBlockingCall'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock2.h(2498,1): error C2375: 'WSAAsyncGetServByName': redefinition; different linkage
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock.h(890): message : see declaration of 'WSAAsyncGetServByName'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock2.h(2526,1): error C2375: 'WSAAsyncGetServByPort': redefinition; different linkage
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock.h(898): message : see declaration of 'WSAAsyncGetServByPort'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock2.h(2554,1): error C2375: 'WSAAsyncGetProtoByName': redefinition; different linkage
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock.h(906): message : see declaration of 'WSAAsyncGetProtoByName'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock2.h(2580,1): error C2375: 'WSAAsyncGetProtoByNumber': redefinition; different linkage
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock.h(913): message : see declaration of 'WSAAsyncGetProtoByNumber'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock2.h(2606,1): error C2375: 'WSAAsyncGetHostByName': redefinition; different linkage
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock.h(920): message : see declaration of 'WSAAsyncGetHostByName'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock2.h(2632,1): error C2375: 'WSAAsyncGetHostByAddr': redefinition; different linkage
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock.h(927): message : see declaration of 'WSAAsyncGetHostByAddr'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock2.h(2662,1): error C2375: 'WSACancelAsyncRequest': redefinition; different linkage
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock.h(936): message : see declaration of 'WSACancelAsyncRequest'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock2.h(2680,1): error C2375: 'WSAAsyncSelect': redefinition; different linkage
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock.h(938): message : see declaration of 'WSAAsyncSelect'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock2.h(4206,1): error C2059: syntax error: ''
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock2.h(4206,1): error C2143: syntax error: missing ';' before ''
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\commctrl.h(69,12): error C2143: syntax error: missing ';' before ''
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\commctrl.h(69,12): error C2447: '': missing function header (old-style formal list?)
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\shobjidl_core.h(7766,32): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\shobjidl_core.h(7766,20): error C2146: syntax error: missing ';' before identifier 'LPTBBUTTONSB'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\shobjidl_core.h(7842,52): error C2061: syntax error: identifier 'LPTBBUTTONSB'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\shobjidl_core.h(14671,49): error C2061: syntax error: identifier 'HIMAGELIST'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\shobjidl.h(6637,20): error C3646: 'himl': unknown override specifier
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\shobjidl.h(6637,20): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\shlobj_core.h(2300,34): error C2065: 'HIMAGELIST': undeclared identifier
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\shlobj_core.h(2300,45): error C2146: syntax error: missing ')' before identifier 'him'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\shlobj_core.h(2771,47): error C2065: 'HIMAGELIST': undeclared identifier
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\shlobj_core.h(2771,59): error C2065: 'phiml': undeclared identifier
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\shlobj_core.h(2771,76): error C2065: 'HIMAGELIST': undeclared identifier
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\shlobj_core.h(2771,88): error C2065: 'phimlSmall': undeclared identifier
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\shlobj_core.h(2771,98): warning C4229: anachronism used: modifiers on data are ignored
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\shlobj_core.h(2771,98): error C2491: 'Shell_GetImageLists': definition of dllimport data not allowed
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\shared\ws2ipdef.h(80,28): error C2079: 'sockaddr_gen::Address' uses undefined struct 'sockaddr'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\shared\ws2ipdef.h(81,33): error C2079: 'sockaddr_gen::AddressIn' uses undefined struct 'sockaddr_in'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\shared\ws2ipdef.h(135,1): warning C4005: 'IP_TOS': macro redefinition
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock.h(349): message : see previous definition of 'IP_TOS'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\shared\ws2ipdef.h(136,1): warning C4005: 'IP_TTL': macro redefinition
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock.h(348): message : see previous definition of 'IP_TTL'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\shared\ws2ipdef.h(137,1): warning C4005: 'IP_MULTICAST_IF': macro redefinition
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock.h(343): message : see previous definition of 'IP_MULTICAST_IF'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\shared\ws2ipdef.h(138,1): warning C4005: 'IP_MULTICAST_TTL': macro redefinition
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock.h(344): message : see previous definition of 'IP_MULTICAST_TTL'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\shared\ws2ipdef.h(139,1): warning C4005: 'IP_MULTICAST_LOOP': macro redefinition
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock.h(345): message : see previous definition of 'IP_MULTICAST_LOOP'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\shared\ws2ipdef.h(140,1): warning C4005: 'IP_ADD_MEMBERSHIP': macro redefinition
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock.h(346): message : see previous definition of 'IP_ADD_MEMBERSHIP'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\shared\ws2ipdef.h(141,1): warning C4005: 'IP_DROP_MEMBERSHIP': macro redefinition
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock.h(347): message : see previous definition of 'IP_DROP_MEMBERSHIP'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\shared\ws2ipdef.h(142,1): warning C4005: 'IP_DONTFRAGMENT': macro redefinition
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock.h(350): message : see previous definition of 'IP_DONTFRAGMENT'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\shared\ws2ipdef.h(222,21): error C2079: '_SOCKADDR_INET::Ipv4' uses undefined struct 'sockaddr_in'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\shared\ws2ipdef.h(738,24): error C2011: 'ip_mreq': 'struct' type redefinition
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\winsock.h(360): message : see declaration of 'ip_mreq'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\shared\ws2ipdef.h(914,21): error C3646: 'protocol': unknown override specifier
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\shared\ws2ipdef.h(914,21): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\ws2tcpip.h(744,9): error C2065: 'WSASetLastError': undeclared identifier
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\ws2tcpip.h(751,9): error C2065: 'WSASetLastError': undeclared identifier
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\ws2tcpip.h(790,9): error C2065: 'WSASetLastError': undeclared identifier
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\ws2tcpip.h(797,9): error C2065: 'WSASetLastError': undeclared identifier
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\ws2tcpip.h(841,9): error C2065: 'WSASetLastError': undeclared identifier
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\ws2tcpip.h(848,9): error C2065: 'WSASetLastError': undeclared identifier
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\ws2tcpip.h(889,9): error C2065: 'WSASetLastError': undeclared identifier
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um\ws2tcpip.h(896,9): error C2065: 'WSASetLastError': undeclared identifier
1>C:\Users\Administrator\source\repos\httpd_dll\httpd_dll\dllmain.cpp(32,72): error C2065: 'MHD_RESPMEM_MUST_COPY': undeclared identifier
1>C:\Users\Administrator\source\repos\httpd_dll\httpd_dll\dllmain.cpp(32,13): error C3861: 'MHD_create_response_from_buffer': identifier not found
1>C:\Users\Administrator\source\repos\httpd_dll\httpd_dll\dllmain.cpp(33,39): error C2065: 'MHD_HTTP_OK': undeclared identifier
1>C:\Users\Administrator\source\repos\httpd_dll\httpd_dll\dllmain.cpp(33,8): error C3861: 'MHD_queue_response': identifier not found
1>C:\Users\Administrator\source\repos\httpd_dll\httpd_dll\dllmain.cpp(34,2): error C3861: 'MHD_destroy_response': identifier not found
1>Done building project "httpd_dll.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
【问题讨论】:
您似乎正在将 C 代码编译为 C++? 可能是因为您在window.h
之后定义了winsock2
标头。之前尝试包含它。
不包括Windows.h
。 Winsock2 标头与您的 goahead
标头发生冲突。不要定义 DllMain,而是将普通函数定义为 dll 的入口点。然后有一个单独的 exe 作为这个 dll 的使用者。这样您就不需要 Windows.h 并且您的 dll 和 exe 都将成功构建。
@bertubezz 你是对的!!!我什至没有想过包含顺序会如此重要!!!
【参考方案1】:
您需要在windows
标头之前包含winsock2
标头。
看; C++ Redefinition Header Files (winsock2.h)
【讨论】:
以上是关于为啥我可以在EXE上编译DLL却不能编译的主要内容,如果未能解决你的问题,请参考以下文章
为啥我不能在 iPhone 上编译引用 vImage 库的代码?
为啥在我的 Mac 上编译的 C++ 库不能在服务器上运行?