4

I'm trying to compile ZeroMQ C binding in order to be able to use it on iPhone, here is my configure options:

./configure --host=arm-apple-darwin --enable-static=yes --enable-shared=no CC=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/arm-apple-darwin10-gcc-4.2.1 CFLAGS="-pipe -std=c99 -Wno-trigraphs -fpascal-strings -O0 -Wreturn-type -Wunused-variable -fmessage-length=0 -fvisibility=hidden -miphoneos-version-min=3.1.2 -gdwarf-2 -mthumb -I/Library/iPhone/include -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.0.sdk -mdynamic-no-pic" CPP=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/cpp AR=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/ar AS=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/as LIBTOOL=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/libtool STRIP=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/strip RANLIB=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/ranlib

It actually configures and compiles fine, but when I add it to Xcode Frameworks section, I get warning: ld: warning: in /path/to/app/libzmq.a, file was built for unsupported file format which is not the architecture being linked (armv7) and a lot of symbol not found errors.

If I change current active architecture from armv6 to armv7, warning message will change it to armv6. What am I doing wrong ?

Thanks, Dan

Jasarien
  • 58,279
  • 31
  • 157
  • 188
Dan
  • 43
  • 1
  • 3

2 Answers2

6

It sounds like you're building a universal armv6/armv7 binary for the iPhone (this is the default, so that makes sense). That means that you need to build a universal library to link against. Build both libraries, and then use lipo to combine the two.

For example, build the armv6 one and place it at armv6/libfoo.a, and the armv7 one at armv7/libfoo.a. Then run

lipo -arch armv6 armv6/libfoo.a -arch armv7 armv7/libfoo.a -output libfoo.a -create

to create the universal library libfoo.a.

Jesse Beder
  • 33,081
  • 21
  • 109
  • 146
  • Thanks for the answer, but how do I define architecture ? arm-apple-darwin10-gcc-4.2.1 doesn't understand -arch option. Btw, lipo -info for my lib says that compiled for x86_64, which is odd. – Dan Sep 01 '10 at 20:39
  • Sorry, I didn't notice you weren't passing the `-arch` option. I'm not sure why it doesn't accept it, but why not try using `/Developer/Platforms/.../gcc` instead? I just looked up my configure commands for the C libraries I've used, and often that works. – Jesse Beder Sep 01 '10 at 21:12
  • 2
    Thanks, I finally was able to compile it right using script from this question - http://stackoverflow.com/questions/1602182/cross-compile-autotools-based-libraries-for-official-iphone-sdk – Dan Sep 02 '10 at 18:41
0

Given the warning message from ld, my guess is you're not compiling the library for the correct platform. And given you're using configure, my guess is you're trying to compile the library outside of Xcode and then bring it into Xcode later to link it in.

Perhaps you could try running configure to set up your headers, but do the actual compilation step inside Xcode?

There are lots of related questions here on SO about compiling third-party (external) C or C++ libraries for use in iPhone projects.

Creating static library for iPhone

TiMidity: need help compiling this library for the iPhone

Community
  • 1
  • 1
Shaggy Frog
  • 27,575
  • 16
  • 91
  • 128
  • Currently the best guide I found for compiling libraries for multiple architectures is this: http://tinsuke.wordpress.com/2011/02/17/how-to-cross-compiling-libraries-for-ios-armv6armv7i386/ – Alper Aug 12 '12 at 10:21