Tôi đang cố gắng xây dựng một thư viện tĩnh mà tôi có thể sử dụng với cả ios3.x và ios4.x. Tôi có thể xây dựng một thư viện tĩnh với ios3.0 mà làm việc với một dự án khác trong ios3.0 nhưng sẽ không biên dịch trong ios4. Điều này cũng đúng từ ios4 đến ios3.Cách xây dựng thư viện tĩnh ios phổ dụng
Dưới đây là làm thế nào để tái tạo:
- mở XCode 3.2.4 và bắt đầu một dự án mới đó là một Cocoa Touch Thư viện tĩnh gọi Library4
- Bấm vào thư mục lớp học và tạo ra một UIViewController mới có tên "TestViewController"
- Nhấp chuột phải vào thư mục Khung, thêm khung hiện có, chọn UIKit
- Trong bảng điều khiển bên trái, mở rộng mục tiêu, nhấp chuột phải vào mục tiêu thư viện của tôi và nhấp vào nhận thông tin. Thay đổi tất cả cấu hình, Thay đổi sdk cơ sở thành mô phỏng iphone 4.0, thay đổi mục tiêu triển khai ios thành ios3.0
- Nhấp vào thư mục Liên kết Thư mục với Thư mục. Trong ngăn bên phải, thay đổi vai trò của cả hai để "Yếu"
- Xây dựng Thư viện
- Mở Xcode 3.2.2 và bắt đầu một Xem dựa trên ứng dụng mới gọi là Library4Test
- Sao chép TestViewController.h để các lớp thư mục
- Sao chép tệp libLibrary4.a vào thư mục khung công tác. Nó tự động được thêm vào giai đoạn liên kết của mục tiêu
- Nhấp chuột phải vào Library4Test Target và nhấp vào nhận thông tin. Trong cờ mối liên kết khác, thêm "-ObjC" và "-all_load"
- trong tiêu đề ứng dụng đại biểu thêm Nhập "TestViewController.h"
TRÊN phương pháp didFinishLaunchingWithOptions ứng dụng của các đại biểu tiêu đề của ứng dụng thêm
TestViewController * kiểm tra = [TestViewController alloc] init;
Compile với ios3.0 giả
Khi tôi biên soạn tôi nhận được:
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
Đối với những người chỉ muốn xây dựng một lib IOS tĩnh: http://stackoverflow.com/questions/3520977/build-fat-static-library-device-simulator-using-xcode-and-sdk-4 –