定位iPhoneSimulator时Xcode中的链接错误 [英] Link errors in Xcode when targeting iPhoneSimulator

查看:42
本文介绍了定位iPhoneSimulator时Xcode中的链接错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更新:

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

/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.

谢谢

-埃里克

解决方案

我终于弄清楚了:

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

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

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

-埃里克

Update:

I just realized that you can get more information by setting the LD_TRACE_ARCHIVES and LD_TRACE_DYLIBS environment variables and then running the linker command directly on the command line. Here is what I am executing and then its output (though I replaced some very long paths and names with <short-text> strings):

/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

So the question is: Why are the .objc_class_name_xxx references not being found even though collect2 is looking into the correct framework locations for the iPhoneSimulator? The whole point here is that this all works correctly, there are no link errors, when targeting the iPhone device itself.

Original Message:

I have an app that compiles and links fine in Xcode when targeting the device itself (iPad), but when I try to target the simulator I get errors indicating that symbols from the frameworks I'm using are not found.

I've seen some older threads related to this, but their suggestions do not work: 1) I did not copy the iPhoneOS SDK frameworks locally 2) I do not have an explicit framework search path 3) However, I do have explicit Library Search Paths, one for the simulator, one for the device. 4) I tried making explicit framework search paths, one for the simulator, one for the device, but that doesn't work either, though the generated gcc command line has the correct -syslib and -F options for the simulator.

I've been stuck with this for quite a while now. Does anyone have any further insight into what might be going on? I'm just linking against 4 basic frameworks, Foundation, UIKit, QuartzCore, and OpenGLES.

Thanks,

-Eric

解决方案

I have finally figured this out:

The problem is in my static libraries, the external references were not being correctly generated because I did not know I needed the -fobjc-abi-version=2 command line option when the modules of the static lib were being built.

The main confusion was that this command line option is not necessary when targeting the device (though I believe it is innocuous in that case), but it is necessary when targeting the simulator.

So if you are creating makefiles for modules that will be linked into an iOS target, make certain to include this option!

-Eric

这篇关于定位iPhoneSimulator时Xcode中的链接错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆