Are there any macros to determine if my code is being compiled to Windows?(是否有任何宏来确定我的代码是否正在编译到 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 上的相同编译器上,如果目标环境是 不是 专门的 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).
如果您知道要构建的环境(来自 makefile),那么您通常可以在命令行中传入 #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".
这里有更多信息
这篇关于是否有任何宏来确定我的代码是否正在编译到 Windows?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:是否有任何宏来确定我的代码是否正在编译到 Windows?
基础教程推荐
- 初始化列表*参数*评估顺序 2021-01-01
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- CString 到 char* 2021-01-01
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
