2012-08-23 65 views
5

我構建了一個靜態庫,它鏈接到其他框架,特別是CoreLocation。我想使用iOS 5提供的功能,但與4.3兼容。靜態庫和 - 弱系統

我在發佈的應用程序崩潰時,我與此錯誤啓動它在iOS設備上的4.3:

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中可選使用的庫。例如:我使用iOS 5的UIKit新通知,但我的部署目標是4.3,所以我需要將此庫標記爲「可選」才能使其工作。 CoreLocation CLGeocoder新的iOS 5類也是如此。

+0

我試圖弱鏈接動態庫,沒有成功。我也嘗試添加動態標誌,但它甚至更糟! – nverinaud

回答

1

問題是UIKeyboardDidChangeFrameNotification在iOS 4上不可用,因此動態加載器(Dyld)失敗。

從靜態庫開發人員的角度來看,您不必做任何事情。 -weak-lSystem標誌應該在爲應用程序使用靜態庫的Xcode項目中設置(請參閱問題中提到的帖子) - 不在靜態庫的項目中。

+0

耶!但是您還需要將多個版本中使用的庫(例如:UIKit或CoreLocation)標記爲可選! – nverinaud