Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cross-compiling open-source c library for iOS and XCode 4.3

I'd like to use the excellent stringencoders library in an iOS application. It's a fairly typical c library, with a configure script generated by autoconf and a makefile.

What I'd like to do is compile arm7 and i386 versions on Mac OSX and then use lipo to make a fat binary.

I'm having trouble figuring out how to persuade the build tools to create my platform-specific binaries. There's a few articles out there and even a few scripts but most of them are targeted at XCode 4.2 and don't work with 4.3.

It looks like it should be possible to create a fairly generic build script that can play nicely with configure and make but I'm at a loss as to where to even start.

Have you successfully done anything like this? I'd love some pointers!

BTW: 'import all the sourcecode into your project' is NOT a viable solution. That way lies madness.

Thanks.

like image 614
Darren Avatar asked Feb 28 '12 13:02

Darren


2 Answers

I've ported a handful of open source C libraries to iOS (see iOS Ports). I've found the most reliable way to port a library is to build a new Xcode project with a build target for a static iOS Library. It is important to note that Apple will not allow your iOS Application to contain dynamic libraries if you plan to distribute your app on the iTunes App store, so you will be unable to use FAT libraries.

These are the steps I usually follow when porting libraries to iOS which usually built with the GNU Autotools:

  1. Run ./configure with appropriate flags on OS X.
  2. Verify that the library builds correctly on OS X using make.
  3. Create a new Xcode project using the iOS Static Library template.
  4. Add the config.h from the previous configure run to the Xcode project.
  5. Read the automake file (Makefile.am), and add the referenced sources in the automaker targets to the Xcode target for the static library.
  6. Copy the CPP flags (i.e. -DHAVE_CONFIG_H) from the automake file to the build settings in Xcode.
  7. Compile in Xcode and start running down errors (usually by adding missing header include paths or missing source files).

The directory structure I usually use is the following:

project/
project/ported-project.xcodeproj
project/project-x.x.x.tar.gz
project/project-x.x.x
project/project -> project-x.x.x

I know this is not exactly what you asked for in your question, however it is rough outline of the steps I've used for years for porting libraries. The benefit of creating an actual Xcode to compile the ported library is that it makes it easier to integrate the library into multiple Xcode iOS applications.

If you need clarification or more detailed instructions, let me know and I"ll try to write up more extensive instructions and update my answer.

like image 77
David M. Syzdek Avatar answered Oct 20 '22 00:10

David M. Syzdek


Is it plausible to add the source files (i.e. .c files) to your project directly?

like image 27
Cthutu Avatar answered Oct 20 '22 00:10

Cthutu