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

6

23

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.

Ethel answered 7/10, 2009 at 1:18 Comment(0)
E
41

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.

Enrollee answered 7/10, 2009 at 1:23 Comment(0)
P
7

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

Privatdocent answered 7/10, 2009 at 1:37 Comment(0)
S
2

If I remember correctly, it's __APPLE__ :)

Spunky answered 7/10, 2009 at 1:21 Comment(1)
I believe this is for both MAC and iOS.Lyophilize
L
1

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
 } 
Lyophilize answered 19/11, 2013 at 10:11 Comment(0)
I
0

old style raw:

#ifdef WIN32
// windows.
#elif __APPLE__
// osx and ios.
#endif
Invitation answered 6/6, 2015 at 15:39 Comment(0)
S
0

This page contains a list of all OS predefined macros.

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

Saldana answered 9/12, 2015 at 18:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.