views:

1420

answers:

2

I'm writing a static library for the iPhone and I'm wondering if what I'm doing is recommended or if I should take a different approach.

The static library I'm writing is dependant on libxml2. libxml2 has a dynamic library (dylib) and a static library (a). I've tried two approaches.

Approach one - When I attempt to link against the static library by adding "-lxml2" to "Other linker flags" the build fails with the following message:

/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/libtool: file: -lxml2 is not an object file (not allowed in a library)

Approach two - I can successfully link against the dynamic library from my static library but I'm not sure if this is allowed (or the proper approach) on the iPhone. Even though I'm building a static library, does Apple allow static libraries that link against dynamic libraries? I'm still learning about static libraries, but from my understanding the code from the dylib would be combined with my code to make one library, thus linking against the dylib shouldn't be an issue.

To summarize:

  • mylibrary.a -> libxml2.a [Doesn't work]
  • mylibrary.a -> libxml2.dylib [Builds, but is this correct and acceptable?]
A: 

Apple doesn't allow you to link frameworks and/or libraries other than that provided with the SDK.

Marco

Marco
+3  A: 

libxml2.dylib is available in the SDK. The right way is to double-click the target node/app in Xcode and then under General click the + under "Linked Libraries"...you should find libxml2.dylib in that list.

0:42 in this Screencast you can see how CoreGraphics is added to a project.

epatel
Right. I understand *how* to link. My question was is it the proper standard for linking to external libraries from static libraries? You make a good point though, one which I kind of overlooked. The libxml2.dylib is distributed with the SDK, thus is probably allowed.
Caged
I'd recommend to not link with static libs of dylibs available from the SDK. They can be used by other framework and you might come into version problems, ie say Foundation.framework do pull in libxml2
epatel