定位iPhoneSimulator时,在Xcode中链接错误

更新:

我刚刚意识到,通过设置LD_TRACE_ARCHIVES和LD_TRACE_DYLIBS环境variables,然后直接在命令行上运行链接器命令,可以获得更多信息。 这是我正在执行,然后它的输出(尽pipe我用<short-text >stringreplace了一些非常长的path和名称):

 /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/g++-4.2 -arch i386 -isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.2.sdk -L<path_to_project>/build/Debug-iphonesimulator -L<path_to_static_libs> -F<path_to_project>/build/Debug-iphonesimulator -filelist <path_to_project>/build/<project_name>.build/Debug-iphonesimulator/<project_name>.build/Objects-normal/i386/<project_name>.LinkFileList -mmacosx-version-min=10.6 --verbose -lproject_lib -Xlinker -objc_abi_version -Xlinker 2 -framework Foundation -framework UIKit -framework OpenGLES -framework QuartzCore -o <path_to_project>/build/Debug-iphonesimulator/<project_name>.app/<project_name> Using built-in specs. Target: i686-apple-darwin10 Thread model: posix gcc version 4.2.1 (Apple Inc. build 5664) /Developer/usr/bin/../libexec/gcc/i686-apple-darwin10/4.2.1/collect2 -dynamic -arch i386 -macosx_version_min 10.6 -syslibroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.2.sdk -weak_reference_mismatches non-weak -o <path_to_project>/build/Debug-iphonesimulator/<project_name>.app/<project_name> -lcrt1.10.6.o -L<path_to_project>/build/Debug-iphonesimulator -L<path_to_static_libs> -L/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.2.sdk/usr/lib -L/Developer/usr/bin/../lib/gcc/i686-apple-darwin10/4.2.1 -L/Developer/usr/bin/../lib/gcc -L/usr/lib/gcc/i686-apple-darwin10/4.2.1 -L/usr/lib/gcc/i686-apple-darwin10/4.2.1 -L/Developer/usr/bin/../lib/gcc/i686-apple-darwin10/4.2.1/../../../i686-apple-darwin10/4.2.1 -L/Developer/usr/bin/../lib/gcc/i686-apple-darwin10/4.2.1/../../.. -L/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.2.sdk/usr/lib/gcc/i686-apple-darwin10/4.2.1/../../.. -filelist <path_to_project>/build/<project_name>.build/Debug-iphonesimulator/<project_name>.build/Objects-normal/i386/<project_name>.LinkFileList -lproject_lib -objc_abi_version 2 -framework Foundation -framework UIKit -framework OpenGLES -framework QuartzCore -lstdc++ -lSystem -lgcc -lSystem -F<path_to_project>/build/Debug-iphonesimulator [Logging for XBS] Used dynamic library: /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.2.sdk/System/Library/Frameworks/Foundation.framework/Foundation [Logging for XBS] Used dynamic library: /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.2.sdk/System/Library/Frameworks/UIKit.framework/UIKit [Logging for XBS] Used dynamic library: /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.2.sdk/System/Library/Frameworks/OpenGLES.framework/OpenGLES [Logging for XBS] Used dynamic library: /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.2.sdk/System/Library/Frameworks/QuartzCore.framework/QuartzCore [Logging for XBS] Used dynamic library: /Developer/usr/lib/gcc/i686-apple-darwin10/4.2.1/libstdc++.dylib [Logging for XBS] Used dynamic library: /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.2.sdk/usr/lib/libSystem.dylib [Logging for XBS] Used indirect dynamic library: /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.2.sdk/usr/lib/libobjc.A.dylib [Logging for XBS] Used indirect dynamic library: /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.2.sdk/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation [Logging for XBS] Used indirect dynamic library: /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.2.sdk/usr/lib/system/libSystem.override.dylib [Logging for XBS] Used indirect dynamic library: /usr/lib/libSystem.B.dylib [Logging for XBS] Used indirect dynamic library: /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.2.sdk/usr/lib/system/libmathCommon.A.dylib [Logging for XBS] Used static archive: <path_to_static_libs>/libproject_lib.a Undefined symbols: ".objc_class_name_NSBundle", referenced from: literal-pointer@__OBJC@__cls_refs@NSBundle in libproject_lib.a(file1.o) ".objc_class_name_UIWindow", referenced from: literal-pointer@__OBJC@__cls_refs@UIWindow in libproject_lib.a(file2.o) ".objc_class_name_UIView", referenced from: .objc_class_name_file3 in libproject_lib.a(file3.o) ".objc_class_name_CAEAGLLayer", referenced from: literal-pointer@__OBJC@__cls_refs@CAEAGLLayer in libproject_lib.a(file3.o) ".objc_class_name_EAGLContext", referenced from: literal-pointer@__OBJC@__cls_refs@EAGLContext in libproject_lib.a(file2.o) literal-pointer@__OBJC@__cls_refs@EAGLContext in libproject_lib.a(file3.o) ".objc_class_name_NSDictionary", referenced from: literal-pointer@__OBJC@__cls_refs@NSDictionary in libproject_lib.a(file3.o) ".objc_class_name_NSNumber", referenced from: literal-pointer@__OBJC@__cls_refs@NSNumber in libproject_lib.a(file3.o) ".objc_class_name_UIScreen", referenced from: literal-pointer@__OBJC@__cls_refs@UIScreen in libproject_lib.a(file2.o) ld: symbol(s) not found collect2: ld returned 1 exit status 

所以问题是:即使collect2正在查找iPhoneSimulator的正确框架位置,为什么没有find.objc_class_name_xxx引用? 这里的重点是,这一切工作正常,没有链接错误,当瞄准iPhone设备本身。

原始信息:

我有一个应用程序编译和链接罚款目标设备本身(iPad)的时候,但是当我尝试目标模拟器,我得到错误,指示从我使用的框架符号没有find。

我已经看到一些相关的老线程,但他们的build议不起作用:1)我没有在本地复制iPhoneOS SDK框架2)我没有一个明确的框架searchpath3)但是,我有明确的库searchpath,一个用于模拟器,一个用于设备。 4)我尝试制作明确的框架searchpath,一个用于模拟器,一个用于设备,但是也不起作用,尽pipe生成的gcc命令行具有用于模拟器的正确的-syslib和-F选项。

我已经坚持了很长一段时间了。 有没有人有进一步的了解可能会发生什么? 我只是连接了4个基础框架,Foundation,UIKit,QuartzCore和OpenGLES。

谢谢,

-Eric

我终于明白了这一点:

问题是在我的静态库中,外部引用没有正确生成,因为我不知道在构build静态库的模块时我需要-fobjc-abi-version = 2命令行选项。

主要的困惑是,这个命令行选项在瞄准设备时是不必要的(尽pipe我相信在这种情况下它是无害的),但是在瞄准模拟器时这是必须的。

所以,如果你正在为将要链接到iOS目标的模块创buildmakefiles,请确保包含此选项!

-Eric