xcode - 使用 CPP 定义构建 pch 文件时出错

标签 xcode gcc uikit c-preprocessor

我们正在为我们的 iPhone 应用程序添加 CoreData 支持。这是一个影响深远的变化(从 SQLitePersistentObject 开始)。为避免分支,我们在 #ifdef block 中运行带有新代码的单个代码线。

当我从我的一个 header (#define CORE_DATA_BUILD) 启用此代码时,一切正常。当我创建一个新目标并在那里定义我的预处理器宏时,我在系统头文件中遇到错误。具体来说; CFBag.h、CFArray.h、CFBinaryHeap.h、CFDictionary.h 和 CFSet.h 都编译失败。

错误是:

expected ';', ',' or ')' before '>' token

我通过复制我现有的应用程序目标然后将 CORE_DATA_BUILD 添加到 GCC-4.2 - 预处理的 C 预处理器定义部分来创建我的新目标。

我非常确定预处理器定义已设置,并且我的宏名称不会与任何 Apple 符号冲突。当我将定义添加到“预编译 header 中未使用的预处理器宏”时,也会出现该错误。我已经清理了构建并删除了预编译的 header ,但我仍然收到错误。

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...

我的 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

知道出了什么问题吗?

最佳答案

    -D<Multiple -Dvalues> 
<command-line>: error: macro names must be identifiers
<command-line>: error: ISO C99 requires whitespace after the macro name

看起来您在某些时候编辑了项目或目标的预处理器宏build设置的所有配置。不同的配置具有不同的值。您没有按取消或统一替换它们,而是以某种方式确认了占位符文本。

Xcode 尽职尽责地传递“”作为预处理器定义,而不是您想要的预处理器定义。

转到目标检查器的 Build 选项卡,找到 Preprocessor Macros,删除其当前值,并将其替换为您真正想要的值。

关于xcode - 使用 CPP 定义构建 pch 文件时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/959422/

相关文章:

ios - 更改从 TestFlight 发送的自动电子邮件中的文本

objective-c - 为 NSMutableArray 分配浮点值

ios - 如何在使用Xcode自动代码签名的同时使用FaSTLane和Crashlytics进行构建?

c++ - solaris 上支持 C++11/14 的 GNU gcc/g++ 编译器版本

iphone - UIImageWriteToSavedPhotosAlbum 导致 EXC_BAD_ACCESS

ios - ld : framework not found AudioUnit, ios9

c - 使用system()执行存在缓冲区溢出漏洞的程序时没有报错信息

c - C语言中如何知道未知类型变量的数据类型?

ios - 使用全宽和动态高度单元重新排序 UICollectionView 时出现 UI 问题

ios - SwiftUI - 表单中的 NavigationLink 单元格在详细信息弹出后保持突出显示