尽管有if语句,Visual Studio仍试图包括Linux标头 [英] Visual Studio trying to include linux headers despite if statement
问题描述
我正在尝试创建一个健壮的头文件,该文件可以在Windows和Linux上进行编译,而无需进行更改.为此,我的include中有一个if语句,看起来像
I am attempting to create a robust header file that will compile on both windows and linux without need for changes. To this end I have an if statement in my includes that looks like
#if (!defined(__WINDOWS__))
#include <sys/time.h>
#include <unistd.h>
#include <pthread.h>
#endif
尽管if语句导致出现类似错误,但我在Visual Studio仍尝试包含这些标头的过程中遇到了问题
I am having problems with visual studio still attempting to include these headers despite the if statement resulting in errors like
error C1083: Cannot open include file: 'sys/time.h'
有没有一种方法可以解决此问题,而无需从标头中删除所有linux代码块?
Is there a way to resolve this issue without removing all the linux blocks of code from the header?
推荐答案
__ WINDOWS __
由 windows.h
定义.因此,您具有圆度.改用它:
__WINDOWS__
is defined by windows.h
. So you have a circularity. Use this instead:
#if defined(_WIN32)
# if defined(_WIN64)
/*64 bit windows*/
# else
/*32 bit windows*/
# endif
#endif
是的,_WIN32 是在64位窗口上定义的.我不骗你.
Yes, _WIN32 is defined on 64 bit windows. I kid you not.
这篇关于尽管有if语句,Visual Studio仍试图包括Linux标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!