Adding the libXML framework to your iPhone App

When working on my first iPhone app, I needed to import the libXML framework into my project. I took a look at a sample app that used the libXML framework, and made sure that the framework list in my project matched the one in the sample project – but for some reason my project wouldn’t compile. It kept complaining that it couldn’t find a libXML header file or some such, and so finally i turned to The Google, and found the answer. I’m sure this stuff is a no-brainer for more experienced Cocoa / iPhone developers, but since I’m neither yet, I thought this was a bit trickier than I expected.

For extra clarity, I’m going to do a simple step by step to show how to get everything working in your project, if you’re having a similar problem:

1. Add the libXML framework to your project in XCode

The proper framework is located in: /Developer/Platforms/Aspen.platform/Developer/SDKs/Aspen1.2.sdk/usr/lib

2. Verify the libXML framework is properly added. This is where I got stumped, because my framework was added by my project wasn’t compiling! It still couldn’t find the proper header files for libXML, even though it was listed as a framework right here!

3. The not-so-obvious step is to add the libXML header files to the header search path in the build properties. To do this, expand the Targets node of your project, and right click your project target file and Get Info. Then add “/usr/include/libxml2” to the header search path in target build settings.

Now compile, and everything should be compiling just fine! You can download the final LibXMLSample project here.