我在 Eclipse 中有一个新的 C++ 项目。我必须手动添加所有包含路径,而且我一定搞砸了。这是我的代码:
#include <winsock2.h>
int main() {
return 0;
}
我可以在 Visual Studio 中编译相同的代码没问题,但是在 Eclipse 中我得到了很多各种各样的编译器错误。我忘了包括一些东西吗?还是我包含的太多?有任何想法吗?
我也确实包含了 WS2_32 库。
我在使用 msvc 2010 编译器的 Windows 8 x64 上。
我搜索了很长一段时间,但所有答案都是关于在包含 windows.h 之前包含 winsock,但我根本不包含 windows.h。另外,这个完全相同的代码在 MSVC 中可以正确编译;因此,我在 Eclipse 中设置错误。
冒着被 tl;dr'ed 的风险,这里是吐:
C:\Program Files (x86)\Windows Kits\8.0\Include\um\winnt.h(1243) : error C2065: 'SAL_sameIRQL' : undeclared identifier
C:\Program Files (x86)\Windows Kits\8.0\Include\um\winnt.h(1246) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
C:\Program Files (x86)\Windows Kits\8.0\Include\um\winnt.h(1246) : error C2513: 'int' : no variable declared before '='
C:\Program Files (x86)\Windows Kits\8.0\Include\um\winnt.h(1246) : error C2146: syntax error : missing ';' before identifier 'EXCEPTION_DISPOSITION'
C:\Program Files (x86)\Windows Kits\8.0\Include\um\winnt.h(1246) : error C2143: syntax error : missing ';' before '__stdcall'
C:\Program Files (x86)\Windows Kits\8.0\Include\um\winnt.h(1246) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
C:\Program Files (x86)\Windows Kits\8.0\Include\um\winnt.h(1246) : error C2377: 'EXCEPTION_DISPOSITION' : redefinition; typedef cannot be overloaded with any other symbol
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\excpt.h(40) : see declaration of 'EXCEPTION_DISPOSITION'
C:\Program Files (x86)\Windows Kits\8.0\Include\um\winnt.h(1252) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
C:\Program Files (x86)\Windows Kits\8.0\Include\um\winnt.h(1254) : error C2143: syntax error : missing ';' before '*'
C:\Program Files (x86)\Windows Kits\8.0\Include\um\winnt.h(1254) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
C:\Program Files (x86)\Windows Kits\8.0\Include\um\winnt.h(1254) : error C2365: 'EXCEPTION_ROUTINE' : redefinition; previous definition was 'function'
C:\Program Files (x86)\Windows Kits\8.0\Include\um\winnt.h(1247) : see declaration of 'EXCEPTION_ROUTINE'
C:\Program Files (x86)\Windows Kits\8.0\Include\um\winnt.h(1254) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
C:\Program Files (x86)\Windows Kits\8.0\Include\um\winnt.h(10749) : error C2146: syntax error : missing ';' before identifier 'Handler'
C:\Program Files (x86)\Windows Kits\8.0\Include\um\winnt.h(10749) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
C:\Program Files (x86)\Windows Kits\8.0\Include\um\winnt.h(10749) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
C:\Program Files (x86)\Windows Kits\8.0\Include\um\winnt.h(16638) : error C2144: syntax error : 'PSLIST_ENTRY' should be preceded by ','
C:\Program Files (x86)\Windows Kits\8.0\Include\um\winnt.h(16646) : error C2144: syntax error : 'PSLIST_ENTRY' should be preceded by ','
C:\Program Files (x86)\Windows Kits\8.0\Include\um\heapapi.h(124) : error C2061: syntax error : identifier '_SA_annotes1'
C:\Program Files (x86)\Windows Kits\8.0\Include\um\heapapi.h(125) : error C2059: syntax error : ')'
C:\Program Files (x86)\Windows Kits\8.0\Include\um\heapapi.h(125) : error C2143: syntax error : missing ')' before ';'
C:\Program Files (x86)\Windows Kits\8.0\Include\um\processthreadsapi.h(204) : error C2144: syntax error : 'LPVOID' should be preceded by ','
C:\Program Files (x86)\Windows Kits\8.0\Include\um\sysinfoapi.h(189) : error C2065: 'SAL_preferredFunction' : undeclared identifier
C:\Program Files (x86)\Windows Kits\8.0\Include\um\sysinfoapi.h(192) : error C2448: '_SA_annotes2' : function-style initializer appears to be a function definition
C:\Program Files (x86)\Windows Kits\8.0\Include\um\sysinfoapi.h(192) : error C2143: syntax error : missing ';' before '__stdcall'
C:\Program Files (x86)\Windows Kits\8.0\Include\um\sysinfoapi.h(351) : error C2065: 'COMPUTER_NAME_FORMAT' : undeclared identifier
C:\Program Files (x86)\Windows Kits\8.0\Include\um\sysinfoapi.h(351) : error C2146: syntax error : missing ')' before identifier 'NameType'
C:\Program Files (x86)\Windows Kits\8.0\Include\um\sysinfoapi.h(351) : warning C4229: anachronism used : modifiers on data are ignored
C:\Program Files (x86)\Windows Kits\8.0\Include\um\sysinfoapi.h(351) : error C2491: 'GetComputerNameExA' : definition of dllimport data not allowed
C:\Program Files (x86)\Windows Kits\8.0\Include\um\sysinfoapi.h(354) : error C2059: syntax error : ')'
C:\Program Files (x86)\Windows Kits\8.0\Include\um\sysinfoapi.h(361) : error C2065: 'COMPUTER_NAME_FORMAT' : undeclared identifier
C:\Program Files (x86)\Windows Kits\8.0\Include\um\sysinfoapi.h(361) : error C2146: syntax error : missing ')' before identifier 'NameType'
C:\Program Files (x86)\Windows Kits\8.0\Include\um\sysinfoapi.h(361) : warning C4229: anachronism used : modifiers on data are ignored
C:\Program Files (x86)\Windows Kits\8.0\Include\um\sysinfoapi.h(361) : error C2491: 'GetComputerNameExW' : definition of dllimport data not allowed
C:\Program Files (x86)\Windows Kits\8.0\Include\um\sysinfoapi.h(364) : error C2059: syntax error : ')'
C:\Program Files (x86)\Windows Kits\8.0\Include\um\sysinfoapi.h(383) : error C2065: 'COMPUTER_NAME_FORMAT' : undeclared identifier
C:\Program Files (x86)\Windows Kits\8.0\Include\um\sysinfoapi.h(383) : error C2146: syntax error : missing ')' before identifier 'NameType'
C:\Program Files (x86)\Windows Kits\8.0\Include\um\sysinfoapi.h(383) : warning C4229: anachronism used : modifiers on data are ignored
C:\Program Files (x86)\Windows Kits\8.0\Include\um\sysinfoapi.h(383) : error C2491: 'SetComputerNameExW' : definition of dllimport data not allowed
C:\Program Files (x86)\Windows Kits\8.0\Include\um\sysinfoapi.h(385) : error C2059: syntax error : ')'
C:\Program Files (x86)\Windows Kits\8.0\Include\um\memoryapi.h(429) : error C2065: 'MEMORY_RESOURCE_NOTIFICATION_TYPE' : undeclared identifier
C:\Program Files (x86)\Windows Kits\8.0\Include\um\memoryapi.h(430) : error C2146: syntax error : missing ')' before identifier 'NotificationType'
C:\Program Files (x86)\Windows Kits\8.0\Include\um\memoryapi.h(430) : warning C4229: anachronism used : modifiers on data are ignored
C:\Program Files (x86)\Windows Kits\8.0\Include\um\memoryapi.h(430) : error C2491: 'CreateMemoryResourceNotification' : definition of dllimport data not allowed
C:\Program Files (x86)\Windows Kits\8.0\Include\um\memoryapi.h(430) : error C2059: syntax error : ')'
C:\Program Files (x86)\Windows Kits\8.0\Include\um\memoryapi.h(536) : error C2061: syntax error : identifier 'PWIN32_MEMORY_RANGE_ENTRY'
C:\Program Files (x86)\Windows Kits\8.0\Include\um\threadpoolapiset.h(341) : error C2061: syntax error : identifier 'PTP_WIN32_IO_CALLBACK'
C:\Program Files (x86)\Windows Kits\8.0\Include\um\bemapiset.h(54) : error C2061: syntax error : identifier 'BEM_FREE_INTERFACE_CALLBACK'
C:\Program Files (x86)\Windows Kits\8.0\Include\um\bemapiset.h(64) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
C:\Program Files (x86)\Windows Kits\8.0\Include\um\bemapiset.h(64) : error C2143: syntax error : missing ',' before '*'
C:\Program Files (x86)\Windows Kits\8.0\Include\um\bemapiset.h(73) : error C2065: 'BEM_REFERENCE' : undeclared identifier
C:\Program Files (x86)\Windows Kits\8.0\Include\um\bemapiset.h(73) : error C2065: 'reference' : undeclared identifier
C:\Program Files (x86)\Windows Kits\8.0\Include\um\bemapiset.h(74) : error C2065: 'BEM_REFERENCE' : undeclared identifier
C:\Program Files (x86)\Windows Kits\8.0\Include\um\bemapiset.h(75) : error C2065: 'copiedReference' : undeclared identifier
C:\Program Files (x86)\Windows Kits\8.0\Include\um\bemapiset.h(75) : warning C4229: anachronism used : modifiers on data are ignored
C:\Program Files (x86)\Windows Kits\8.0\Include\um\bemapiset.h(75) : error C2078: too many initializers
C:\Program Files (x86)\Windows Kits\8.0\Include\um\bemapiset.h(81) : error C2065: 'BEM_REFERENCE' : undeclared identifier
C:\Program Files (x86)\Windows Kits\8.0\Include\um\bemapiset.h(82) : error C2065: 'reference' : undeclared identifier
C:\Program Files (x86)\Windows Kits\8.0\Include\um\bemapiset.h(82) : warning C4229: anachronism used : modifiers on data are ignored
C:\Program Files (x86)\Windows Kits\8.0\Include\um\bemapiset.h(82) : error C2182: 'BemFreeReference' : illegal use of type 'void'
C:\Program Files (x86)\Windows Kits\8.0\Include\um\bemapiset.h(82) : fatal error C1903: unable to recover from previous error(s); stopping compilation