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

时间:2011-02-15 22:18:36

标签: xcode ios ios-simulator

更新

我刚刚意识到您可以通过设置LD_TRACE_ARCHIVES和LD_TRACE_DYLIBS环境变量然后直接在命令行上运行链接器命令来获取更多信息。这是我正在执行的,然后是它的输出(虽然我用<short-text&gt;字符串替换了一些非常长的路径和名称):

/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的正确框架位置,也找不到.objc_class_name_xxx引用?这里的重点是,这一切都正常,在定位iPhone设备时没有链接错误。

原始讯息:

我有一个应用程序,在针对设备本身(iPad)时编译和链接很好的Xcode,但当我尝试瞄准模拟器时,我得到错误,表明我找不到我正在使用的框架中的符号。

我见过一些与之相关的旧线程,但他们的建议不起作用: 1)我没有在本地复制iPhoneOS SDK框架 2)我没有明确的框架搜索路径 3)但是,我确实有明确的库搜索路径,一个用于模拟器,一个用于设备。 4)我尝试制作显式的框架搜索路径,一个用于模拟器,一个用于设备,但这也不起作用,尽管生成的gcc命令行具有正确的模拟器的-syslib和-F选项。

我已经坚持了很长一段时间了。有没有人对可能发生的事情有进一步的了解?我只是链接4个基本框架,Foundation,UIKit,QuartzCore和OpenGLES。

谢谢,

-Eric

1 个答案:

答案 0 :(得分:5)

我终于弄明白了:

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

主要的困惑是,在定位设备时不需要此命令行选项(虽然我认为在这种情况下它是无害的),但在定位模拟器时是必要的。

因此,如果您要为将链接到iOS目标的模块创建makefile,请确保包含此选项!

-Eric