MinGW的不是定义WIN32,在preprocessor指令错误 [英] MinGW not defining WIN32, error in preprocessor directives

查看:297
本文介绍了MinGW的不是定义WIN32,在preprocessor指令错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的mingw32-make来编译项目到Windows,它依赖于一个名为libevent2项目。我不断收到此错误 -

  util.h:69:25:致命错误:SYS / socket.h中:没有这样的文件或目录

显然来自Linux API文件试图被列入,这将无法在Windows工作。然而,在进一步调查中,我发现,如果没有定义的 WIN32这个文件应该只包括在内。

 的#ifdef WIN32
 #包括LT&;&winsock2.h GT;
#其他
 #包括LT&; SYS / socket.h中>
#万一


解决方案

您应该使用 _WIN32 键,可能还需要检查 __ CYGWIN __

 #如果定义_WIN32 ||定义__CYGWIN__

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

解决方案

You should use _WIN32 and may also want to check for __CYGWIN__

#if defined _WIN32 || defined __CYGWIN__

这篇关于MinGW的不是定义WIN32,在preprocessor指令错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆