Christian J. B.
Christian J. B.

Reputation: 501

Importing complex.h header file in Xcode .c header file produces compilation errors

I have a project containing a mixture of Objective c and c files. In one of the c header files I am trying to import complex.h. Xcode generates 13 compilation errors connected to NSObjRuntime.h:

NSObjRuntime.h

Parse Issue Expected identifier or '('

Parse Issue Unknown type name 'NSString'...

More compilation errors are produced from NSZone.h.

It looks to me like the errors are coming from Objective C code being unrecognized in a .c file. Should I convert my c files to objective c in order to import complex.h or is there a more elegant solution?

Upvotes: 3

Views: 1408

Answers (1)

justin
justin

Reputation: 104698

It looks to me like the errors are coming from Objective C code being unrecognized in a .c file.

exactly.

Should I convert my c files to objective c in order to import complex.h or is there a more elegant solution?

there is no need to use objc in this example. therefore, there is no need to compile it as objc. complex.h does not require or include objc headers.

you simply do not include objc headers in your c translations.

if this include is coming from the prefix header, you can use:

#if defined(__OBJC__)
#import <Foundation/Foundation.h>
#endif

if it's imported via another header you have included, you will have to consider your include dependencies. sometimes there are unnecessary includes, sometimes you can get away using #if defined(__OBJC__).

Upvotes: 3

Related Questions