Search code examples
iphonexcodefftw

How do I link third party libraries like fftw3 and sndfile to an iPhone project in Xcode?


I'm trying to link third party libraries like fftw3 and sndfile to my iPhone project in Xcode3.2. I got it working in a regular Mac project by setting the "Header Search Path" to "/usr/local/include" and the "Other Linker Flags" to "-lfftw3 -lsndfile" under the project build configuration. However, it gave me "library not found for -lfftw3" with exit code 1 error message when I tried to build it in the iPhone project using the same settings.

Does apple not allow this on the iPhone? Is there a way to get around this?


Solution

  • You need to build your libraries as universal static libraries. The process varies from library to library but it generally goes something like this.

    1. build the library as a static lib for the different platforms (armv6 and i386 at the least)
    2. use lipo to create a universal library from the individual static libraries built above
    3. drag and drop the universal lib into your xcode project
    4. drag and drop the header files into your xcode project

    Step 1 is generally the trickiest since many libraries have different build procedures. It is usually done by setting the proper compiler flags to use the iphone sdk instead of the system wide compiler.