【问题标题】:Link errors in Xcode when targeting iPhoneSimulator针对 iPhoneSimulator 时 Xcode 中的链接错误
【发布时间】:2011-06-27 23:11:40
【问题描述】:

更新:

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

/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 设备本身时,这一切都正常工作,没有链接错误。

原文:

我有一个应用程序可以在 Xcode 中以设备本身 (iPad) 为目标进行编译和链接,但是当我尝试以模拟器为目标时,我收到错误消息,表明未找到我正在使用的框架中的符号。

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

我已经被这个问题困扰了很长时间了。有没有人对可能发生的事情有任何进一步的了解?我只是链接了 4 个基本框架,Foundation、UIKit、QuartzCore 和 OpenGLES。

谢谢,

-埃里克

【问题讨论】:

    标签: xcode ios ios-simulator


    【解决方案1】:

    我终于明白了:

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

    主要的困惑是,当以设备为目标时,这个命令行选项不是必需的(尽管我认为在这种情况下它是无害的),但在以模拟器为目标时却是必需的。

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

    -埃里克

    【讨论】:

    • omfg 我一遍又一遍地问同样的问题。非常感谢您分享您的答案。
    猜你喜欢
    • 2013-03-12
    • 2013-08-12
    • 1970-01-01
    • 2013-03-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多