Reputation: 2616
I have a C++11 codebase I compile with gcc 4.6 from MacPorts on OS X Lion. I also need to compile and link some OS-specific Objective C/C++ files to make the final executable. I would like to use the same compiler version to compile the whole project, but I cannot get the MacPorts version 4.6 of gcc to recognize Objective-C files; it always attempts to interpret them as C++ code and ignores the .mm file extension. (Compiling these files does work with the Xcode version of gcc, just not the MacPorts one. However that gcc is version 4.2 and I want to compile everything with gcc 4.6 or later.)
Forget IDE's or build tools: I get the same result from a commandline invocation of the compiler. That is, I record a commandline that works for compiling .mm files with the Apple gcc, verify yes it does work from the commandline, then run the identical command with nothing changed but the compiler used and it doesn't work. What am I missing?
Upvotes: 1
Views: 894
Reputation: 2616
It appears maybe the specific problem I'm having might be due to an Apple specific language extension, as the specific error I get is the same as this quote from a blog post:
After adding this, I was good for about 30 seconds until I get to the portion of my project where some COCOA Objective-C UI stuff was being compiled.
/Developer/SDKs/MacOSX10.7.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSTask.h:75:24: error: expected unqualified-id before '^' token /Developer/SDKs/MacOSX10.7.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSTask.h:75:24: error: expected ')' before '^' token
Uh oh. I know what this is. This is the Apple "blocks" language extension. It appears that blocks are used in a bunch of the system header files. I don't think there is going to be a way to get around this using MacPorts gcc. The FSF gcc just doesn’t know about blocks. Fortunately for me, I didn't have anything in the Objective C/C++ code that needed to be compiled with gcc 4.6 so I just had this target compile using clang.
Upvotes: 1