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

前端 未结 6 1693
别跟我提以往
别跟我提以往 2021-02-02 10:31

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

相关标签:
6条回答
  • 2021-02-02 11:02

    This page contains a list of all OS predefined macros.

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

    0 讨论(0)
  • 2021-02-02 11:14

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

    0 讨论(0)
  • 2021-02-02 11:17

    If I remember correctly, it's __APPLE__ :)

    0 讨论(0)
  • 2021-02-02 11:21

    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.

    0 讨论(0)
  • 2021-02-02 11:21

    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
     } 
    
    0 讨论(0)
  • 2021-02-02 11:26

    old style raw:

    #ifdef WIN32
    // windows.
    #elif __APPLE__
    // osx and ios.
    #endif
    
    0 讨论(0)
提交回复
热议问题