views:

5879

answers:

3

There's an open source library that I would like to use for my iPhone app. The library is written in C and compiles with Makefiles. I would like to use a static library.

If I add the .a file to my project dependencies, it works well with the simulator, but it doesn't link when targeting the iPhone SDK (certainly because the .a file is compiled for an Intel platform).

What GCC compiler flags should I use to compile a static library for the iPhone SDK? I thought that the '-arch' option would provide me with an iPhone architecture, but no luck.

Any help would be appreciated.

+2  A: 

Try compiling with arm-apple-darwin-gcc as your GCC application. You can then use lipo to merge the 2 static libraries (arm and 386) together so that the development on the sim versus the device is seamless.

Thanks for the info. I'm still trying to make the library to compile with arc-apple-darwin-gcc...
Martin Cote
A: 

After several attempts to use the arm GCC compiler with the tips provided here, I gave up. In my case, it is much simpler to simply port the library to XCode than trying to compile a static library for the iPhone.

Martin Cote
+5  A: 

For autoconf based library, I would vote for Christopher Stawarz's build script:

http://pseudogreen.org/blog/build_autoconfed_libs_for_iphone.html

With this script, you can automate the whole process with single command, and easily come up with library binaries for different platforms, such as iPhoneOS 2.0/2.1/2.2/2.2.1 and iPhoneSimulator 2.0/2.1/2.2/2.2.1.

However, due to the change of Xcode 3.1, the $(SDKROOT) build setting had became some short names like "macosx10.5", "iphoneos2.2.1" or "iphonesimulator2.2.1". So, the way he mentioned in the article about setting search path in Xcode for library and header will not work (in Xcode 3.1). You will need to hard code the path by yourself.

digdog