Reputation: 16345
I have an XCode project (Objective-C) to which I'm trying to add a C++ library I've coded earlier. As soon as I add a single .cpp
or .mm
file, the build process will trip up on random things, usually when building the prefix header. The same thing happens when I include .c
files. Basically, I can only use .m
files in my target. The last error I've got was:
SDKpath/public/CoreGraphics.framework/Headers/CGFont.h:53:
error: expected constructor, destructor, or type conversion before ';' token
The code at that line being:
CG_EXTERN CGFontGetGlyphsForUnichars(CGFontRef font, void* chars, CGGlyph* glyphs, int len)
CG_AVAILABLE_STARTING(__MAC_10_2, __IPHONE_2_0);
I'm pretty sure that the code isn't what caused that issue, but I can't figure out what is wrong with my build settings. If I get rid of that include, then the build process will trip on the first bit of Objective-C code it gets to.
This is my prefix header:
#ifdef __OBJC__
#import <Foundation/Foundation.h>
#import <CoreGraphics/CoreGraphics.h>
#import <IOSurface/IOSurfaceAPI.h>
#import "CGColorUtil.h"
#endif
Upvotes: 1
Views: 343
Reputation: 16345
I'm an idiot. For some reason the return type was missing from the function.
CG_EXTERN void CGFontGetGlyphsForUnichars(CGFontRef font, void* chars, CGGlyph* glyphs, int len)
CG_AVAILABLE_STARTING(__MAC_10_2, __IPHONE_2_0);
Upvotes: 1
Reputation: 2661
You need to set the compile target as Objective-C++ or change the file extension to .mm of your C/C++ code files. Same thing for an entire library.
I'm also pretty sure that the compiler always defines the OBJC macro, so if you don't want to include that code you need to find a different way to hide it from the compiler.
Upvotes: 0