我构建一个静态库,链接其他框架,特别是CoreLocation。我想使用iOS 5提供的功能,但与4.3兼容。
当我在4.3版的iOS设备上启动它时,我的应用程序崩溃时出现此错误:
Date/Time: 2012-08-22 16:44:53.900 +0200
OS Version: iPhone OS 4.3.3 (8J3)
Report Version: 104
Exception Type: EXC_BREAKPOINT (SIGTRAP)
Exception Codes: 0x00000001, 0xe7ffdefe
Crashed Thread: 0
Dyld Error Message:
Symbol not found: _UIKeyboardDidChangeFrameNotification
我遇到的问题在这篇文章中有描述:iOS 4 app crashes at startup on iOS 3.1.3: Symbol not found: __NSConcreteStackBlock。
但是在构建静态库时如何处理?我设置-weak-lSystem标志时无法编译。这是一个痕迹:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: -dynamic not specified, -all_load invalid
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: -dynamic not specified the following flags are invalid: -ObjC
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: can't locate file for: -weak-lSystem
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: file: -weak-lSystem is not an object file (not allowed in a library)
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: file: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.1.sdk/usr/lib/libxml2.2.dylib is a dynamic library, not added to the static library
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: file: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.1.sdk/usr/lib/libxml2.2.dylib is a dynamic library, not added to the static library
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: file: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.1.sdk/usr/lib/libz.dylib is a dynamic library, not added to the static library
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: file: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.1.sdk/usr/lib/libz.dylib is a dynamic library, not added to the static library
Command /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool failed with exit code 1
解决
请参阅下面接受的答案,不要忘记将不同版本中使用的库标记为Xcode中的Optional。例如:我使用iOS 5的UIKit新通知,但我的部署目标是4.3,所以我需要将此库标记为可选,以使工作正常。 CoreLocation CLGeocoder新推出的iOS 5类也是如此。
答案 0 :(得分:1)
问题是UIKeyboardDidChangeFrameNotification在iOS 4上不可用,因此动态加载程序(Dyld)失败。
从静态库开发人员的角度来看,您不必执行任何操作。 -weak-lSystem标志应该在Xcode项目中设置,该项目使用应用程序的静态库(参见问题中提到的帖子) - 而不是在静态库的项目中。