0

我在我的 iPhone 项目中包含了合并sqlite 代码,并删除了对 iPhone sqlite 框架的引用。

我的主要目标编译得很好。

我有第二个目标是使用google 框架进行单元测试。编译时我得到:

错误:“@”标记之前的语法错误

我不明白为什么。我已将两个项目都设置为 sdk 2。

更新:我包括到 sqlite 代码和谷歌的链接。在我添加 sqlite 代码之前,我必须添加目标编译好几个月。我没有发布示例代码,因为我收到 1263 错误 - 所以我在所有文件中都收到错误 - 但这是一个示例回溯:

@class NSString, Protocol; <== ERROR HERE

追溯:

        cd /Users/trtrrtrtr/mamcx/projects/JhonSell/iPhone
        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.0 -x c-header -arch i386 -fmessage-length=0 -pipe -std=c99 -Wno-trigraphs -fpascal-strings -fasm-blocks -O0 -Wreturn-type -Wunused-variable -D__IPHONE_OS_VERSION_MIN_REQUIRED=20000 -isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator2.2.1.sdk -fvisibility=hidden -mmacosx-version-min=10.5 -gdwarf-2 -iquote /Users/trtrrtrtr/mamcx/projects/JhonSell/iPhone/build/JhonSell.build/Debug-iphonesimulator/Testing.build/Testing-generated-files.hmap -I/Users/trtrrtrtr/mamcx/projects/JhonSell/iPhone/build/JhonSell.build/Debug-iphonesimulator/Testing.build/Testing-own-target-headers.hmap -I/Users/trtrrtrtr/mamcx/projects/JhonSell/iPhone/build/JhonSell.build/Debug-iphonesimulator/Testing.build/Testing-all-target-headers.hmap -iquote /Users/trtrrtrtr/mamcx/projects/JhonSell/iPhone/build/JhonSell.build/Debug-iphonesimulator/Testing.build/Testing-project-headers.hmap -F/Users/trtrrtrtr/mamcx/projects/JhonSell/iPhone/build/Debug-iphonesimulator -F/Volumes/CrashReporter-1.0-rc2/CrashReporter-iPhone -F/Users/trtrrtrtr/mamcx/projects/JhonSell/iPhone -I/Users/trtrrtrtr/mamcx/projects/JhonSell/iPhone/build/Debug-iphonesimulator/include -I/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator2.2.1.sdk/usr/include/libxml2 "-I/Developer/RemObjects Software/Source" -I/Users/trtrrtrtr/mamcx/projects/JhonSell/iPhone/build/JhonSell.build/Debug-iphonesimulator/Testing.build/DerivedSources/i386 -I/Users/trtrrtrtr/mamcx/projects/JhonSell/iPhone/build/JhonSell.build/Debug-iphonesimulator/Testing.build/DerivedSources -c /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator2.2.1.sdk/System/Library/Frameworks/UIKit.framework/Headers/UIKit.h -o /var/folders/EA/EAmC8fuyElexZfnpnjdyr++++TI/-Caches-/com.apple.Xcode.501/SharedPrecompiledHeaders/UIKit-dqqtnrciylhdtjbmyglpcezxchmz/UIKit.h.gch
    In file included from /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator2.2.1.sdk/System/Library/Frameworks/Foundation.framework/Headers/Foundation.h:12,
                     from /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator2.2.1.sdk/System/Library/Frameworks/UIKit.framework/Headers/UIAccelerometer.h:8,
                     from /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator2.2.1.sdk/System/Library/Frameworks/UIKit.framework/Headers/UIKit.h:9:
    /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator2.2.1.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:120: 
error: syntax error before '@' token
4

3 回答 3

2

我终于弄清楚了问题所在。

我将它从 iPhone 目标复制到测试目标:

GCC_DYNAMIC_NO_PIC = NO
GCC_OPTIMIZATION_LEVEL = 0
GCC_PRECOMPILE_PREFIX_HEADER = YES
GCC_PREFIX_HEADER = JhonSell_Prefix.pch
GCC_PREPROCESSOR_DEFINITIONS = DEBUG

但是为什么之前我没有问题?我真的不明白。

于 2009-08-05T15:56:07.763 回答
1

几乎没有什么可做的,我的猜测是从 C/C++ 实现文件中包含一个 Objective C 头文件,因此用 C/C++ 而不是 Objective C/Objective C++ 编译头文件。

查看您更新的信息,您实际上正在编译一个头文件,即 UIKit.h。编译器不知道它是什么类型的头文件,所以它默认为 C,它当然没有 @class,因此语法错误。

所以你必须弄清楚为什么 Xcode 想要在你的第二个目标中编译UIKit.h。

于 2009-08-05T01:14:02.787 回答
0

您的命令行正在将文件gcc编译为文件。.h.gch

    /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc-4.0
    # ...
    -x c-header -arch i386 -fmessage-length=0 -pipe -std=c99 -Wno-trigraphs # ...
    # ...
    # THE INPUT FILE:
    /Developer/Platforms/iPhoneSimulator.platform/Developer/
      SDKs/iPhoneSimulator2.2.1.sdk/System/Library/Framework/
      UIKit.framework/Headers/UIKit.h
    # THE OUTPUT FILE:
    -o /var/folders/EA/EAmC8fuyElexZfnpnjdyr++++TI/
       -Caches-/com.apple.Xcode.501/
       SharedPrecompiledHeaders/UIKit-dqqtnrciylhdtjbmyglpcezxchmz/UIKit.h.gch

UIKit.hinto UIKit.h.gch:将头文件翻译成“预编译”的头文件,因为它是标记化的形式,所以可以更快地包含在内。

看起来编译器不知道它应该预编译头文件;它以某种方式配置不正确,只是将其视为要实际编译的代码,并且因为代码是Objective C而窒息。

于 2012-03-21T04:47:59.637 回答