我想建立一個靜態庫,我可以使用ios3.x和ios4.x.我可以用ios3.0構建一個靜態庫,它可以與ios3.0中的另一個項目一起工作,但不會在ios4中編譯。從ios4到ios3也是如此。如何建立通用的ios靜態庫
下面是如何重現:
- 開放的XCode 3.2.4,並開始一個新的項目,這是一個可可觸摸靜態庫稱爲Library4
- 單擊類文件夾,並創建一個名爲「TestViewController」新的UIViewController
- 右鍵單擊Frameworks文件夾,添加現有框架,選擇UIKit
- 在左側窗格中,展開目標,右鍵單擊我的圖書館目標並單擊獲取信息。更改爲所有配置,將基礎sdk更改爲iphone模擬器4.0,將ios部署目標更改爲ios3.0
- 單擊具有二進制文件的鏈接庫文件夾。在右窗格中,兩者的角色改變爲「弱」
- 構建庫
- 開放的Xcode 3.2.2和啓動名爲Library4Test
- 複製TestViewController.h的類新的基於瀏覽應用程序文件夾
- 將libLibrary4.a文件複製到框架文件夾。它會自動添加到目標的鏈接器階段
- 右鍵單擊Library4Test目標並單擊獲取信息。在其他連接標誌,添加「-ObjC」和「-all_load」
- 在應用程序委託頭添加導入「TestViewController.h」
在App委託頭的應用的didFinishLaunchingWithOptions方法中添加
TestViewController *測試= [TestViewController alloc] init;
編譯ios3.0模擬器
我編譯時得到:
Ld build/Debug-iphonesimulator/library4Test.app/library4Test normal i386
cd /Users/test/Documents/Testing/library4Test
setenv MACOSX_DEPLOYMENT_TARGET 10.5
setenv PATH "/Developer/GrandpaIPhone/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Developer/GrandpaIPhone/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Developer/GrandpaIPhone/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc-4.2 -arch i386 -isysroot /Developer/GrandpaIPhone/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.1.3.sdk -L/Users/test/Documents/Testing/library4Test/build/Debug-iphonesimulator -L/Users/test/Documents/Testing/library4Test -F/Users/test/Documents/Testing/library4Test/build/Debug-iphonesimulator -filelist /Users/test/Documents/Testing/library4Test/build/library4Test.build/Debug-iphonesimulator/library4Test.build/Objects-normal/i386/library4Test.LinkFileList -mmacosx-version-min=10.5 -framework Foundation -framework UIKit -framework CoreGraphics -llibrary4_1 -o /Users/test/Documents/Testing/library4Test/build/Debug-iphonesimulator/library4Test.app/library4Test
Undefined symbols:
"_objc_msgSendSuper2", referenced from:
-TestViewController didReceiveMemoryWarning in liblibrary4_1.a(TestViewController.o)
-TestViewController viewDidUnload in liblibrary4_1.a(TestViewController.o)
-TestViewController dealloc in liblibrary4_1.a(TestViewController.o)
"__objc_empty_vtable", referenced from:
_OBJC_METACLASS_$_TestViewController in liblibrary4_1.a(TestViewController.o)
_OBJC_CLASS_$_TestViewController in liblibrary4_1.a(TestViewController.o)
"_OBJC_CLASS_$_UIViewController", referenced from:
_OBJC_CLASS_$_TestViewController in liblibrary4_1.a(TestViewController.o)
"_OBJC_METACLASS_$_UIViewController", referenced from:
_OBJC_METACLASS_$_TestViewController in liblibrary4_1.a(TestViewController.o)
".objc_class_name_TestViewController", referenced from:
[email protected][email protected][email protected] in library4_1os3TestAppDelegate.o
"_OBJC_METACLASS_$_NSObject", referenced from:
_OBJC_METACLASS_$_TestViewController in liblibrary4_1.a(TestViewController.o)
ld: symbol(s) not found
collect2: ld returned 1 exit status
對於只是希望建立一個靜態IOS庫的人來說:http://stackoverflow.com/questions/3520977/build-fat-static-library-device-simulator-using-xcode-and-sdk-4 – 2012-10-08 08:25:32