xcode 使用 CPP 定义构建 pch 文件时出错
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/959422/
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
Error building pch file with CPP definitions
提问by Rog
We're adding CoreData support to our iPhone app. It's a far reaching change (moving from SQLitePersistentObject). To avoid branching, we are running a single codeline with the new code within #ifdef
blocks.
我们正在向我们的 iPhone 应用程序添加 CoreData 支持。这是一个影响深远的变化(从 SQLitePersistentObject 开始)。为避免分支,我们在#ifdef
块内运行带有新代码的单个代码行。
When I enable this code from one of my headers (#define CORE_DATA_BUILD) everything works fine. When I create a new target and define my preprocessor macro there, I get errors in the system headers. Specifically; CFBag.h, CFArray.h, CFBinaryHeap.h, CFDictionary.h and CFSet.h all fail to compile.
当我从我的头文件之一 (#define CORE_DATA_BUILD) 启用此代码时,一切正常。当我创建一个新目标并在那里定义我的预处理器宏时,我在系统头文件中出现错误。具体来说; CFBag.h、CFArray.h、CFBinaryHeap.h、CFDictionary.h 和 CFSet.h 都无法编译。
The error is:
错误是:
expected ';', ',' or ')' before '>' token
expected ';', ',' or ')' before '>' token
I created my new target by copying my existing app target and then adding CORE_DATA_BUILD to the CPre-processor definitions section of GCC-4.2 - Preprocessing.
我通过复制我现有的应用程序目标,然后将 CORE_DATA_BUILD 添加到GCC-4.2 - 预处理的C预处理器定义部分来创建我的新目标。
I'm pretty sure the pre-processor definition is set up and my macro name doesn't clash with any Apple symbols. The error also manifests when I add my define to "Preprocessor Macros Not Used In Precompiled Headers". I have cleaned the build and removed the precompiled headers but I still get the error.
我很确定预处理器定义已设置并且我的宏名称不会与任何 Apple 符号发生冲突。当我将定义添加到“预编译头文件中未使用的预处理器宏”时,该错误也会出现。我已经清理了构建并删除了预编译的头文件,但我仍然收到错误消息。
Invocation and error output from Xcode is:
Xcode 的调用和错误输出是:
ProcessPCH /var/folders/Ay/AyBvIizJERGjIMkWxjcIfU+++TI/-Caches-/com.apple.Xcode.501/SharedPrecompiledHeaders/UIKit-fzghyhumbyslqcedmtegbkgafwpy/UIKit.h.gch /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.0.sdk/System/Library/Frameworks/UIKit.framework/Headers/UIKit.h normal i386 objective-c com.apple.compilers.gcc.4_2
cd /Users/rog/Development/Groove
setenv PATH "/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc-4.2 -x objective-c-header -arch i386 -fmessage-length=0 -pipe -std=c99 -Wno-trigraphs -fpascal-strings -fasm-blocks -O0 -Werror -Wreturn-type -Wunused-variable -DCOREDATA -D<Multiple -Dvalues> -D__IPHONE_OS_VERSION_MIN_REQUIRED=30000 -isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.0.sdk -fvisibility=hidden -mmacosx-version-min=10.5 -gdwarf-2 -iquote /Users/rog/Development/Groove/build/Groove.build/Debug-iphonesimulator/Tests.build/Tests-generated-files.hmap -I/Users/rog/Development/Groove/build/Groove.build/Debug-iphonesimulator/Tests.build/Tests-own-target-headers.hmap -I/Users/rog/Development/Groove/build/Groove.build/Debug-iphonesimulator/Tests.build/Tests-all-target-headers.hmap -iquote /Users/rog/Development/Groove/build/Groove.build/Debug-iphonesimulator/Tests.build/Tests-project-headers.hmap -F/Users/rog/Development/Groove/build/Debug-iphonesimulator -F/Users/rog/Development/Groove -I/Users/rog/Development/Groove/build/Debug-iphonesimulator/include -I/Users/rog/Development/Groove/build/Groove.build/Debug-iphonesimulator/Tests.build/DerivedSources/i386 -I/Users/rog/Development/Groove/build/Groove.build/Debug-iphonesimulator/Tests.build/DerivedSources -c /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.0.sdk/System/Library/Frameworks/UIKit.framework/Headers/UIKit.h -o /var/folders/Ay/AyBvIizJERGjIMkWxjcIfU+++TI/-Caches-/com.apple.Xcode.501/SharedPrecompiledHeaders/UIKit-fzghyhumbyslqcedmtegbkgafwpy/UIKit.h.gch
<command-line>: error: macro names must be identifiers
<command-line>: error: ISO C99 requires whitespace after the macro name
In file included from /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.0.sdk/System/Library/Frameworks/CoreFoundation.framework/Headers/CoreFoundation.h:39,
from /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.0.sdk/System/Library/Frameworks/Foundation.framework/Headers/Foundation.h:6,
from /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.0.sdk/System/Library/Frameworks/UIKit.framework/Headers/UIAccelerometer.h:8,
from /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.0.sdk/System/Library/Frameworks/UIKit.framework/Headers/UIKit.h:9:
/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.0.sdk/System/Library/Frameworks/CoreFoundation.framework/Headers/CFArray.h:173: error: expected ';', ',' or ')' before '>' token
/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.0.sdk/System/Library/Frameworks/CoreFoundation.framework/Headers/CFArray.h:359: error: expected ';', ',' or ')' before '>' token
In file included from /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.0.sdk/System/Library/Frameworks/CoreFoundation.framework/Headers/CoreFoundation.h:40,
etc...
My Prefix.pch file is standard:
我的 Prefix.pch 文件是标准的:
//
// Prefix header for all source files of the 'Groove' target in the 'Groove' project
//
#ifdef __OBJC__
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#endif
Any idea what's going wrong?
知道出了什么问题吗?
采纳答案by cdespinosa
-D<Multiple -Dvalues>
<command-line>: error: macro names must be identifiers
<command-line>: error: ISO C99 requires whitespace after the macro name
It looks like at some point you edited All Configurations of the Preprocessor Macros build setting of your project or target. Different configurations had different values. Rather than pressing Cancel or replacing them uniformly, you somehow confirmed the placeholder text .
看起来您在某个时候编辑了项目或目标的预处理器宏构建设置的所有配置。不同的配置有不同的值。您没有按取消或统一替换它们,而是以某种方式确认了占位符 text 。
Xcode is dutifully passing "<Multiple" and "Values>" as preprocessor definitions, instead of the preprocessor definitions you want.
Xcode 尽职尽责地传递“<Multiple”和“Values>”作为预处理器定义,而不是您想要的预处理器定义。
Go to the target inspector Build tab, find Preprocessor Macros, delete its current value, and replace it with the value you really want.
转到目标检查器 Build 选项卡,找到 Preprocessor Macros,删除其当前值,并将其替换为您真正想要的值。
回答by 1800 INFORMATION
Bit of a stab in the dark here - are you generating a precompiled header file? Have you rebuilt the precompiled header file since you changed the preprocessor symbol? You may be seeing a difference in the symbol as built into the precompiled header, and the symbol as seen in the other compilation units.
在这里暗中刺伤 - 您是否正在生成预编译的头文件?自从更改了预处理器符号后,您是否重建了预编译头文件?您可能会发现预编译头中内置的符号与其他编译单元中的符号有所不同。
回答by cdespinosa
Please post the invocationline of the compiler, not just the error; it tells us infinitely more. The error you cited is typical when an upstream error confuses the compiler when it's #importing downstream header files; it obviously doesn't mean there are errors in CFBag.h et al.
请贴出编译器的调用行,不要只贴出错误;它告诉我们更多。当上游错误在#importing下游头文件时混淆编译器时,您引用的错误是典型的错误;这显然并不意味着 CFBag.h 等文件中存在错误。
My suspicion is that when you created a different target, you got a different Prefix Header File for that target, and it's not set up correctly; compare the Prefix Header File build settings for the old and new targets, and compare the files themselves.
我怀疑当你创建一个不同的目标时,你为那个目标得到了一个不同的前缀头文件,而且它没有正确设置;比较旧目标和新目标的前缀头文件构建设置,并比较文件本身。
One common error is to include Objective-C header files from a C++ project. That doesn't work; you need to turn your .cpp files into .mm files if you want to intermix Objective-C and C++. But C++ should be able to #include CoreFoundation header files.
一个常见的错误是包含来自 C++ 项目的 Objective-C 头文件。那行不通;如果您想混合使用 Objective-C 和 C++,您需要将 .cpp 文件转换为 .mm 文件。但是 C++ 应该能够 #include CoreFoundation 头文件。