C MinGW未定义WIN32,预处理器指令出错

C MinGW未定义WIN32,预处理器指令出错,c,mingw,c-preprocessor,C,Mingw,C Preprocessor,我正在使用mingw32 make将一个项目编译到Windows,它依赖于一个名为libevent2的项目。我一直收到这个错误- util.h:69:25: fatal error: sys/socket.h: No such file or directory 显然,Linux API中的一个文件正试图被包括在内,这在Windows上不起作用。但是,经过进一步调查,我发现只有在未定义WIN32时才应包含此文件。 #ifdef WIN32 #include <winsock2.h>

我正在使用mingw32 make将一个项目编译到Windows,它依赖于一个名为libevent2的项目。我一直收到这个错误-

util.h:69:25: fatal error: sys/socket.h: No such file or directory
显然,Linux API中的一个文件正试图被包括在内,这在Windows上不起作用。但是,经过进一步调查,我发现只有在未定义WIN32时才应包含此文件。

#ifdef WIN32
 #include <winsock2.h>
#else
 #include <sys/socket.h>
#endif
#ifdef WIN32
#包括
#否则
#包括
#恩迪夫

您应该使用
\u WIN32
,还可能需要检查
\uuuuuucygwin\uuuuuu

#if defined _WIN32 || defined __CYGWIN__

您确定没有任何未定义的
WIN32
?我安装的MinGW(本网站4.6.1)明确规定:

C:\temp>gcc -E -dM test.c | find /i "win"
#define _WIN32 1
#define __WINT_MAX__ 65535
#define _WINT_T
#define __WINT_MIN__ 0
#define __WIN32 1
#define __WINNT 1
#define __WINNT__ 1
#define __WIN32__ 1
#define __SIZEOF_WINT_T__ 2
#define WIN32 1                 // <-- right here
#define __WINT_TYPE__ short unsigned int
#define WINNT 1
默认情况下,和<>代码> /d“win32”< /> >被放入VisualStudioC++项目。


有关详细信息,请参阅。

“您的项目”?确保已定义WIN32。“”需要cygwin,而不仅仅是mingw32。@John抱歉,“一个项目”。“确保定义了WIN32”是什么意思?您使用的是哪个版本的MinGW?调用编译器的命令行是什么?
#ifndef WIN32
#define WIN32
#endif