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

I have an Xcode project for my Cocoa application. All this is Objective-C.

The 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 a project, there are thousands of errors. All of them are complaints about syntax errors. For instance:

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

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

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

Thanks Mark

+6
source share
2 answers

if the files you compile do not contain anything, then your problem is likely in the prefix header (extension: pch)

so you just include your language based library (in pch):

 #ifdef __OBJC__ #import <Foundation/Foundation.h> #endif 
+15
source

Check the .pch file. It imports some Objective-C header without proper preprocessor protection.

You need to make sure that the Objective-C header or framework imported into your precompiled header looks something like this:

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

Source: https://habr.com/ru/post/887956/


All Articles