Organizing code within XCode is fairly straightforward when working on simple iPhone Apps. However, as you scale up the Apps (or what you're doing with core framework code) you will need to start diving into iPhone Static Libraries under XCode. Unfortunately this is an area that's not well documented but the process is very straight forward if you follow the XCode documentation on the XCode Build System - specifically how to use Targets within a project (or cross-project references) to link static libraries together.
The process of creating and setting up an iPhone static library took about 15 minutes following the XCode documentation. However, after creating my static library target and putting some files into it, I ran into a very cryptic error:
/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/libtool failed with exit code 1
Ya, wonderful. Very helpful. I was able to troubleshoot the problem by resorting to the xcodebuild command line to build my library target:
xcodebuild -target <LibraryTargetName>
The resulting error messages made it obvious what the problem was:
/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/libtool: can't locate file for: -licucore
/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/libtool: file: -licucore is not an object file (not allowed in a library)
Command /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/libtool failed with exit code 1
Command /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/libtool failed with exit code 1
** BUILD FAILED **
Yup, the default target setup linker options for an -licucore - which won't work (at least for iPhone 3.0 SDK). Fixing the issue is a cakewalk now that the cause is known. Select the static library target in the main project window, right click and select "Get Info" (or hit Cmd-I), select the "Build" tab, and in the search box at top, type "Other Linker". You'll see the Other Linker Flags setting with the -licucore flag set. Simply delete the flag and the project will link and build without problems.
Note: a second gotcha is Apps that you link your iPhone static library to should include the "-ObjC" Other Linker Flag option if your static library contains Objective C code (see
Technical Q&A QA1490). If you use Categories you may also need the -all_load flag (try compiling without it, and if it fails, add and recompile... it creates fatter Apps but is a workaround if you can't link otherwise).
Comments [0]