我的 iPhone 应用程序无法链接到 iPhone 模拟器时遇到一些问题。它告诉我有未定义的符号:
Undefined symbols for architecture i386:
".objc_class_name_NSRunLoop", referenced from:
pointer-to-literal-objc-class-name in SampleBrowser.cpp.o
".objc_class_name_NSDate", referenced from:
pointer-to-literal-objc-class-name in SampleBrowser.cpp.o
".objc_class_name_NSAutoreleasePool", referenced from:
pointer-to-literal-objc-class-name in SampleBrowser.cpp.o
pointer-to-literal-objc-class-name in libRenderSystem_GLES2Static.a(OgreEAGL2Window.mm.o)
".objc_class_name_UIApplication", referenced from:
pointer-to-literal-objc-class-name in SampleBrowser.cpp.o
pointer-to-literal-objc-class-name in libOIS.a(iPhoneInputManager.mm.o)
".objc_class_name_NSObject", referenced from:
.objc_class_name_AppDelegate in SampleBrowser.cpp.o
".objc_class_name_UIView", referenced from:
.objc_class_name_SampleBrowserGestureView in SampleBrowser.cpp.o
.objc_class_name_InputDelegate in libOIS.a(iPhoneInputManager.mm.o)
.objc_class_name_EAGL2View in libRenderSystem_GLES2Static.a(OgreEAGL2View.mm.o)
".objc_class_name_UIScreen", referenced from:
pointer-to-literal-objc-class-name in libOIS.a(iPhoneInputManager.mm.o)
pointer-to-literal-objc-class-name in libRenderSystem_GLES2Static.a(OgreEAGL2Support.mm.o)
".objc_class_name_UIAccelerometer", referenced from:
pointer-to-literal-objc-class-name in libOIS.a(iPhoneInputManager.mm.o)
pointer-to-literal-objc-class-name in libOIS.a(iPhoneAccelerometer.mm.o)
但这些看起来像是我链接的框架中的 Objective-C 类的名称。我想做一些挖掘工作,所以我使用 nm 查看我链接的框架的符号列表。例如
josh$ nm /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.1.sdk/System/Library/Frameworks/Foundation.framework/Foundation -arch i386 -g | grep objc_class
001a4500 S $ld$add$os10.4$.objc_class_name_NSArray
001a4501 S $ld$add$os10.4$.objc_class_name_NSCalendar
001a4502 S $ld$add$os10.4$.objc_class_name_NSData
001a4503 S $ld$add$os10.4$.objc_class_name_NSDate
001a4504 S $ld$add$os10.4$.objc_class_name_NSDateComponents
001a4505 S $ld$add$os10.4$.objc_class_name_NSDictionary
001a4506 S $ld$add$os10.4$.objc_class_name_NSEnumerator
001a4507 S $ld$add$os10.4$.objc_class_name_NSException
001a4508 S $ld$add$os10.4$.objc_class_name_NSInputStream
001a4509 S $ld$add$os10.4$.objc_class_name_NSInvocation
001a450a S $ld$add$os10.4$.objc_class_name_NSLocale
001a450b S $ld$add$os10.4$.objc_class_name_NSMethodSignature
001a450c S $ld$add$os10.4$.objc_class_name_NSMutableArray
001a450d S $ld$add$os10.4$.objc_class_name_NSMutableData
001a450e S $ld$add$os10.4$.objc_class_name_NSMutableDictionary
001a450f S $ld$add$os10.4$.objc_class_name_NSMutableSet
001a4510 S $ld$add$os10.4$.objc_class_name_NSNull
001a4511 S $ld$add$os10.4$.objc_class_name_NSObject
001a4512 S $ld$add$os10.4$.objc_class_name_NSOutputStream
001a4513 S $ld$add$os10.4$.objc_class_name_NSRunLoop
001a4514 S $ld$add$os10.4$.objc_class_name_NSSet
001a4515 S $ld$add$os10.4$.objc_class_name_NSStream
001a4516 S $ld$add$os10.4$.objc_class_name_NSTimeZone
001a4517 S $ld$add$os10.4$.objc_class_name_NSTimer
001a4548 S $ld$add$os10.4$.objc_class_name_NSURL
001a4518 S $ld$add$os10.4$.objc_class_name_NSUserDefaults
001a4549 S $ld$add$os10.5$.objc_class_name_NSURL
001a454a S $ld$hide$os10.4$.objc_class_name_NSFileWrapper
001a454b S $ld$hide$os10.5$.objc_class_name_NSFileWrapper
001a454c S $ld$hide$os10.6$.objc_class_name_NSFileWrapper
现在,这个符号列表让我觉得框架档案正在导出链接器正在寻找的类。唯一不同的是这个 $ld$add$os10.4$ 前缀。我想知道为什么它在那里,它意味着什么,这是否可能导致我的问题?
编辑:看起来这是我的问题: 针对 iPhoneSimulator 时 Xcode 中的链接错误
简而言之,省略编译器标志 -fobjc-abi-version=2 会导致不同的符号命名。