Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C macro for OS X version (Lion or not) detection?

Tags:

c

macos

gcc

Is there a predefined C macro for detecting the version of OS X? I know __APPLE__ and __MACH__ exist, but those are binary. Is there a specific value for __APPLE_CC__ that indicates Lion?

In particular, Lion added a definition of getline() to <stdio.h> in Lion and it would be nice to be able to detect whether or not code was compiling on Lion or not to work around compilation errors.

Specifically, I'm referring to building Unix C code in Bash (outside of XCode).

like image 752
Mike Avatar asked Nov 06 '11 03:11

Mike


2 Answers

The Availability.h macros allow you to check for compile- and run-time version dependencies. See the discussion here.

like image 187
Ned Deily Avatar answered Oct 18 '22 08:10

Ned Deily


Check in /usr/include/AvailabilityMacros.h - it contains macros such as:

#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_7
    #define DEPRECATED_IN_MAC_OS_X_VERSION_10_7_AND_LATER    DEPRECATED_ATTRIBUTE
#else
    #define DEPRECATED_IN_MAC_OS_X_VERSION_10_7_AND_LATER
#endif

I came across this stuff because 'openssl/sha1.h' has been slathered with 'deprecated' attributes for Lion, so compiling git gets warnings galore.

like image 24
Jonathan Leffler Avatar answered Oct 18 '22 07:10

Jonathan Leffler