I am using mingw32-make to compile a project to Windows, which depends on a project called libevent2. I keep receiving this error -
util.h:69:25: fatal error: sys/socket.h: No such file or directory
Obviously a file from the Linux API is trying to be included, which won't work on Windows. Upon further investigation I find however that this file should only be included if WIN32 isn't defined.
#ifdef WIN32
#include <winsock2.h>
#else
#include <sys/socket.h>
#endif
Are you sure there's nothing undefining
WIN32
? My installation of MinGW (4.6.1 at this site) definitely defines it:Try passing the
-E -dM
options to verify if your MinGW compiler is (or isn't) pre-defining theWIN32
macro.Note that strictly speaking,
WIN32
should not be predefined by the compiler (since it's in the user's namespace) - only_WIN32
should.WIN32
should be set by the SDK being used and/or by the build environment - that's the way it works in Microsoft's compilers.For example, there's the following sequence in
windef.h
"and
/D "WIN32"
is put into Visual Studio C++ projects by default.See https://stackoverflow.com/a/662543/12711 for more details.
You should use
_WIN32
and may also want to check for__CYGWIN__