开发者

Link errors in Xcode when targeting iPhoneSimulator

开发者 https://www.devze.com 2023-02-11 04:59 出处:网络
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.H

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

0

精彩评论

暂无评论...
验证码 换一张
取 消