Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 928
Mark Avatar asked May 12 '11 19:05

Mark


2 Answers

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
like image 113
justin Avatar answered Nov 15 '22 23:11

justin


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
like image 38
Jonathan Grynspan Avatar answered Nov 15 '22 23:11

Jonathan Grynspan