Objective-C添加C文件,大量错误问题

项目中添加C语言文件后编译出现大量错误,因为工程中有pch文件,作为预编译头文件,Objective-C和C都会引用到它,而里面都是Objective-C代码,C编译器是编译不了的,所以就出现了大量错误。

the pch is included as a prefix into both C and ObjC files. So my C files were getting Foundation.h which of course would never work :)

所以要在pch文件中加上:

#ifdef __OBJC__
#import ...
#endif

屏蔽C对它的引用。
参考链接

你可能感兴趣的:(Objective-C添加C文件,大量错误问题)