xcode 添加C文件导致pch错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19723392/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 04:14:37  来源:igfitidea点击:

Adding C file causes pch error

objective-ccxcode

提问by Alex I

I have an XCodeproject with objective-Cfiles. If I add a new (empty) C fileand try to build, I get a large number of errors right away while building a precompiled header, in ProcessPCH step. The errors are "fatal error: Could not build module 'Foundation'", and things in Foundation.hnot being found. Remove the C file and it builds again. What is going on, and how to fix it?

我有一个XCode包含objective-C文件的项目。如果我添加一个新的(空的)C file并尝试构建,在 ProcessPCH 步骤中构建预编译头时,我会立即收到大量错误。错误是“致命错误:无法构建模块‘基础’”,以及Foundation.h未找到的东西。删除 C 文件并重新构建。这是怎么回事,如何解决?

(XCode 5.0, OSX 10.8.4)

(XCode 5.0,OSX 10.8.4)

EDITI have tried Clean and Clean build folder, no effect.

编辑我试过清理和清理构建文件夹,没有效果。

EDITSetting Precompile prefix header = Noresults in a bunch of syntax errors instead, in stuff like NSObject.h(and other Foundation framework header).

编辑设置会Precompile prefix header = No导致一堆语法错误,比如NSObject.h(和其他 Foundation 框架标头)。

EDITUser Cy-4AH figured it out: there needs to be #ifdef __OBJC__around the wholepch file.

编辑用户 Cy-4AH 想通了:需要#ifdef __OBJC__围绕整个pch 文件。

回答by Cy-4AH

Surround #import's with preprocessor directive #ifdef __OBJC__ #endif

Surround#import带有预处理器指令#ifdef __OBJC__ #endif