Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Proper way to link against libraries from libraries for the iPhone/CocoaTouch

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?]
like image 436
Caged Avatar asked Mar 08 '09 05:03

Caged


People also ask

What is Cocoa Touch framework in iOS?

Cocoa Touch is the application development environment for building software programs to run on iOS for the iPhone and iPod Touch, iPadOS for the iPad, watchOS for the Apple Watch, and tvOS for the Apple TV, from Apple Inc. Cocoa Touch. Developer(s) Apple Inc. Operating system.

What is library in iOS?

App Library shows your apps organized into categories, such as Creativity, Social, and Entertainment. The apps you use most are near the top of the screen and at the top level of their categories, so you can easily locate and open them.


1 Answers

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.

like image 135
epatel Avatar answered Oct 07 '22 02:10

epatel