I'm running 10.9.2 and installed GCC 4.8.2 through MacPorts (sudo port install gcc48 +universal
) and cannot compile Objective-C code that sets -mmacosx-version-min=10.8
or any other version and includes Foundation. If I set the version to 10.9
or don't set it at all, it works.
Here's the code:
#include <Foundation/Foundation.h>
int main() {
return 0;
}
Here's the command:
g++-mp-4.8 objctest.m -mmacosx-version-min=10.8 -framework Foundation
The error I receive is:
In file included from /usr/include/Availability.h:148:0,
from /opt/local/lib/gcc48/gcc/x86_64-apple-darwin13/4.8.2/include-fixed/math.h:46,
from /System/Library/Frameworks/CoreFoundation.framework/Headers/CoreFoundation.h:19,
from /System/Library/Frameworks/Foundation.framework/Headers/Foundation.h:6,
from objctest.m:1:
/System/Library/Frameworks/Foundation.framework/Headers/NSUserNotification.h:16:45: error: expected ',' or '}' before '__attribute__'
NSUserNotificationActivationTypeReplied NS_AVAILABLE(10_9, NA) = 3
^
Even if I add the -isysroot arg like so:
-isysroot `xcodebuild -version -sdk macosx Path`
It still doesn't work (although it gives errors relative to the SDK).
Is the MacPorts GCC borked or is this an issue with GCC and OS X headers?
My end goal is to compile a full program (Qt gui) for 10.6 that uses C++11 features, so GCC is a must as 10.6 doesn't have libc++.
Update 1: OS X's headers apply __attribute__((weak_import))
to an individual enumeration type, and GCC apparently doesn't support this:
For an enum, struct or union type, you may specify attributes either between the enum, struct or union tag and the name of the type, or just past the closing curly brace of the definition.
I don't want to patch SDK headers, so looks like this is a no-go.
Update 2: It is a documented Clang extension:
Clang allows attributes to be written on individual enumerators. This allows enumerators to be deprecated, made unavailable, etc. The attribute must appear after the enumerator name and before any initializer