我在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中设置错误。
冒着被诅咒的风险,这是呕吐:
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
答案 0 :(得分:1)
如果可能,请尝试使用7.1或7.0 SDK而不是8.0 / 8.1。我们在使用8.0 SDK时遇到了类似的问题。