Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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.

share|improve this question
    
Just to be explicit, what toolset are you looking for a solution for? It appears that you are looking for an XCode 4.3 solution, but that isn't clear. –  Peter M Feb 28 '12 at 14:19
    
Thanks, I've changed the title to clarify –  Darren Feb 28 '12 at 14:53
    
Unless you aren't aware of what a cross-compiler is, this sounds like a configuration issue specific to Xcode 4.3. True? –  Garen Apr 8 '12 at 4:13

4 Answers 4

up vote 1 down vote accepted

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.

share|improve this answer

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

share|improve this answer

Objective C is a superset of C so i am surprised that the code did not work directly out of the box in XCode 4. Are you missing out something there ? just suggesting

share|improve this answer

Generate your project files using gyp: http://code.google.com/p/gyp/ I use it to share libraries between win/osx/ios and linux (pi).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.