macos 对于 OS X 特定代码,我应该使用什么 C 预处理器条件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1529031/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What C preprocessor conditional should I use for OS X specific code?
提问by klynch
What C preprocessor conditional should I use for OS X specific code? I need to include a specific library if I am compiling for OS X or a different header if I am compiling for Linux.
对于 OS X 特定代码,我应该使用什么 C 预处理器条件?如果我为 OS X 编译,我需要包含一个特定的库,如果我为 Linux 编译,我需要包含一个不同的头文件。
I know there is __APPLE__
but I don't know if that is a current conditional for OS X 10.x.
我知道有,__APPLE__
但我不知道这是否是 OS X 10.x 的当前条件。
回答by Mark Rushakoff
This list of operating system macros says the presence of both__APPLE__
and __MACH__
indicate OSX.
此操作系统宏列表说明两者的存在__APPLE__
并 __MACH__
指示 OSX。
Also confirmed at line 18 of part of the source for fdisk
.
回答by Mark Bessey
__APPLE__
will tell you you're compiling on an Apple platform. Unless you need to support MacOS versions before OS X, that should be good enough. Alternately, you could use __APPLE__
and __MACH__
to make sure you're compiling on OS X.
__APPLE__
会告诉你你正在 Apple 平台上编译。除非您需要支持 OS X 之前的 MacOS 版本,否则应该足够了。或者,您可以使用__APPLE__
并__MACH__
确保您在 OS X 上进行编译。
回答by Thibault Martin-Lagardette
If I remember correctly, it's __APPLE__
:)
如果我没记错的话,是__APPLE__
:)
回答by Naseef Ur Rahman
This code example may help you -
此代码示例可能会帮助您 -
if defined(__APPLE__)
#include "TargetConditionals.h"
if (!defined(TARGET_OS_IPHONE) && !defined(TARGET_IPHONE_SIMULATOR))
{
//write your OSX specific code here
}
回答by ingconti
old style raw:
老式原始:
#ifdef WIN32
// windows.
#elif __APPLE__
// osx and ios.
#endif