2009-08-04 12 views
0

我在我的iPhone项目中包含了amalgamation sqlite代码,并删除了对iPhone sqlite框架的引用。error:'@'token之前的语法错误(为什么?)

我的主要目标编译正常。

我有第二个单元测试的目标是google framework。编译时我得到:

error: syntax error before '@' token

我不明白为什么。我已将这两个项目设置为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 
+2

如何发布代码?没有多少我可以说,否则... – 2009-08-04 23:37:56

+1

你至少应该发布错误发生的代码。错误消息应该告诉你它在哪一行。 – sth 2009-08-04 23:49:52

+1

和众神来自天堂,并告诉我们你在说什么。我不这么认为 – 2009-08-05 01:49:38

回答

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 

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

1

很少去我的猜测是包含来自C/C++实现文件的Objective C头文件,因此在C/C++而不是Objective C/Objective C++中编译头文件。

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

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

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 

I.e. UIKit.h转换为UIKit.h.gch:将头文件转换为“预编译”头文件,可以更快地包含它,因为它是以标记化的形式。

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