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
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