What C preprocessor conditional should I use for OS X specific code?

不想你离开。 提交于 2019-12-03 06:50:00

问题


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.

I know there is __APPLE__ but I don't know if that is a current conditional for OS X 10.x.


回答1:


This list of operating system macros says the presence of both __APPLE__ and __MACH__ indicate OSX.

Also confirmed at line 18 of part of the source for fdisk.




回答2:


__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.




回答3:


If I remember correctly, it's __APPLE__ :)




回答4:


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
 } 



回答5:


old style raw:

#ifdef WIN32
// windows.
#elif __APPLE__
// osx and ios.
#endif



回答6:


This page contains a list of all OS predefined macros.

For mac OSX both the __APPLE__ && __MACH__ need to be defined.



来源:https://stackoverflow.com/questions/1529031/what-c-preprocessor-conditional-should-i-use-for-os-x-specific-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!