Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 641
klynch Avatar asked Oct 07 '09 01:10

klynch


4 Answers

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.

like image 173
Mark Rushakoff Avatar answered Nov 15 '22 06:11

Mark Rushakoff


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

like image 37
Mark Bessey Avatar answered Nov 15 '22 08:11

Mark Bessey


If I remember correctly, it's __APPLE__ :)

like image 33
Thibault Martin-Lagardette Avatar answered Nov 15 '22 06:11

Thibault Martin-Lagardette


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
 } 
like image 43
Naseef Chowdhury Avatar answered Nov 15 '22 07:11

Naseef Chowdhury