I'm trying to build a static library that I can use with both ios3.x and ios4.x. I can build a static library with ios3.0 that works with another project in ios3.0 but won't compile in ios4. The same is true going from ios4 to ios3.
Here's how to recreate:
IN the app delegate header's application's didFinishLaunchingWithOptions method add
TestViewController *test = [TestViewController alloc] init;
Compile with ios3.0 simulator
When I compile I get:
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
An XCFramework can be either static or dynamic and can include headers.
A static library is a collection of compiled object files combined into a single library file, that may be linked into an app or framework target just like single object files are linked.
NOTE: Dynamic libraries outside of a framework bundle, which typically have the file extension . dylib, are not supported on iOS, watchOS, or tvOS, except for the system Swift libraries provided by Xcode. You're not allowed to create these, as this will get your app rejected.
What are the differences between static and dynamic libraries? Static libraries, while reusable in multiple programs, are locked into a program at compile time. Dynamic, or shared libraries, on the other hand, exist as separate files outside of the executable file.
Not sure exactly, but it looks like a linking problem (all those .o things). Here's how I set up my iOS static library. It's a very simple thing, but it works.
Build your static library. By default it will build in /usr/local/lib
Now create a symbolic link for easy access to your new library. An easy way is to open your terminal and run the following commands:
cd ~
ln -s /usr/local/lib
Now open the Xcode project in which you want to use your library. Create a group called Libraries or something like that, ctrl-click and use 'Add existing files' to add the library. It will be called something like libYourLibrary.a When you run your project, you'll get a linking error. So double-click the project file, go to Build >> All configurations and add the following value to the "Library Search Paths" setting: ~/lib
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With