Creating static library for iPhone

11,196

Solution 1

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.

Solution 2

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.

Solution 3

Just compile it normally using the x86 sdk (iphone simulator) then again using the platform for arm/ios (arm-xxx-xxx) then combine both static libs in a .a using "LIPO" (command-line tool). Works a treat and it's simpler than reinventing the wheel (at least for those smallish libs).... i did that with liblo and libdmtx and i'm not having any problems and it took me like 10 minutes to do both... :-)

Share:
11,196
Martin Cote
Author by

Martin Cote

Graphics Engineer at Unity3D.

Updated on June 04, 2022

Comments

  • Martin Cote
    Martin Cote almost 2 years

    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.

  • Martin Cote
    Martin Cote over 15 years
    Thanks for the info. I'm still trying to make the library to compile with arc-apple-darwin-gcc...
  • Alper
    Alper almost 12 years
    Anybody have a more recent answer to this issue?