是否有任何宏来确定,如果我的code被编译到Windows? [英] Are there any macros to determine if my code is being compiled to Windows?
问题描述
我想检测我编译的操作系统是否为Windows。有一个简单的宏我可以检查验证?
I would like to detect whether the OS I'm compiling on is Windows. Is there a simple macro I can check to verify that?
推荐答案
的 的
一些编译器提供的宏来表示一个Windows编译环境。但是,这些将有所不同的编译器编译器,甚至在Windows上相同的编译器,如果目标环境的不的专门窗口。通常它的 __ __ WIN32
,但并非总是如此。
Some compilers offer macros to indicate a Windows build environment. But these will vary from compiler to compiler, and even on the same compiler on Windows if the target environment is not exclusively windows. Usually it's __WIN32__
, but not always.
#if defined (__WIN32__)
// Windows stuff
#endif
有时也可以是 _WIN32
, __ CYGWIN32 __
,或者可能只是编译器指示器( _MSC_VER
)。
Sometimes it can be _WIN32
, __CYGWIN32__
, or possibly just the compiler indicator (_MSC_VER
).
如果你知道你将建设(从生成文件)的环境中,那么你可以在的#define
通常通过在命令行上,如 G ++ -D __WIN32__ yourfile.c
If you know the environment you'll be building in (from the makefile) then you can usually pass in the #define
on the command line, like "g++ -D __WIN32__ yourfile.c
".
这里小的详细信息。
这篇关于是否有任何宏来确定,如果我的code被编译到Windows?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!