我正在尝试构建一个可以与 ios3.x 和 ios4.x 一起使用的静态库。我可以使用 ios3.0 构建一个静态库,该库可以与 ios3.0 中的另一个项目一起使用,但不会在 ios4 中编译。从 ios4 到 ios3 也是如此。
以下是如何重新创建:
- 打开 XCode 3.2.4 并启动一个新项目,它是一个名为 Library4 的 Cocoa Touch 静态库
- 单击类文件夹并创建一个名为“TestViewController”的新 UIViewController
- 右键单击 Frameworks 文件夹,添加现有框架,选择 UIKit
- 在左侧面板中,展开目标,右键单击我的库目标,然后单击获取信息。更改所有配置,将base sdk更改为iphone模拟器4.0,将ios部署目标更改为ios3.0
- 单击带有二进制文件的链接库文件夹。在右侧窗格中,将两者的角色更改为“弱”
- 建立图书馆
- 打开 Xcode 3.2.2 并启动一个名为 Library4Test 的新的基于视图的应用程序
- 将 TestViewController.h 复制到类文件夹
- 将 libLibrary4.a 文件复制到 frameworks 文件夹。它会自动添加到目标的链接器阶段
- 右键单击 Library4Test 目标并单击获取信息。在其他链接器标志中,添加“-ObjC”和“-all_load”
- 在应用程序委托标头中添加 Import "TestViewController.h"
在应用程序委托标头的应用程序的 didFinishLaunchingWithOptions 方法中添加
TestViewController *test = [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:
literal-pointer@__OBJC@__cls_refs@TestViewController 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