Mark
Mark

Reputation: 1447

Adding an empty .c file to Xcode Cocoa project causes thousands of errors

I have an Xcode project for my Cocoa application. It's all Objective-C so far.

Problems started after I added a new .c File from the menu (Add C file and header): test.c and header test.h.

When I try to compile the project now there are thousands of errors. All of them are complaints about syntax errors. For example:

NSObjCRuntime.h: Expected identifier or '(' before '@' token

Both new files, test.c and test.h, do not contain any code, only the default header comments. Something must be really broken with my project configuration. When I remove these two files the project compiles just fine.

The project language is set to C99. Is there anything else I could check?

Thanks, Mark

Upvotes: 7

Views: 1745

Answers (2)

Jonathan Grynspan
Jonathan Grynspan

Reputation: 43472

Check your .pch file. It's importing some Objective-C header without the appropriate preprocessor guard.

You must make sure any Objective-C header or framework imported in your precompiled header looks something like this:

#if defined(__OBJC__)
    #import <Cocoa/Cocoa.h>
    #import <CoreData/CoreData.h>
    #import "MyConstants.h"
    ...
#endif

Upvotes: 5

justin
justin

Reputation: 104698

if the files you compile include nothing, then your problem is likely in the prefix header (extension: pch)

so you just wrap your library includes based on the language (in the pch):

#ifdef __OBJC__
#import <Foundation/Foundation.h>
#endif

Upvotes: 17

Related Questions