Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Build GMP for iOS

Tags:

ios

iphone

ios5

gmp

I need to use GMP in an iphone program I'm working on, but don't really know where to begin. I know that I have to build a version for the device and a version for the simulator, but that is as much as I know. I've tried looking around but haven't been able to find much.

Has anyone here successfully build GMP for iphone that would care to guide me through the process?

I saw Building GMP for iOS but it is not working for me. I thought I had built it successfully using:

./configure CC="/Developer/Platforms/iPhoneOS.platform/Developer/usr/llvm-gcc-4.2/bin/llvm-gcc-4.2" CXX="/Developer/Platforms/iPhoneOS.platform/Developer/usr/llvm-gcc-4.2/bin/llvm-g++-4.2" CPP="/Developer/Platforms/iPhoneOS.platform/Developer/usr/llvm-gcc-4.2/bin/llvm-gcc-4.2 -E" LD="$IOS/usr/bin/ld" CPPFLAGS="-arch armv7 -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk -miphoneos-version-min=4.2" AR="$IOS/usr/bin/ar" NM="$IOS/usr/bin/nm" NMEDIT="$IOS/usr/bin/nmedit" LIBTOOL="$IOS/usr/bin/libtool" LIPO="$IOS/usr/bin/lipo" OTOOL="$IOS/usr/bin/otool" RANLIB="$IOS/usr/bin/ranlib" STRIP="$IOS/usr/bin/strip" --disable-shared --enable-static --prefix=$IOS/usr/local --host=none-apple-darwin10

Then make install.

In /usr/local/lib I have libgmp.a. But when I drag to to xcode when I go to compile it tells me:

ignoring file /Users/daniel/Desktop/libgmp.a, file was built for archive which is not the architecture being linked (armv7) (I dropped in my desktop for some reason, then dragged to into my xcode project)

This is driving me nuts. Can anyone help? Bear in mind I'm a complete noob using the these tools.

Assuming I get help and I can make this work. How do I go about turning it into a framework that will work on an armv6, armv7, and simulator(i386)?

Thanks in advance.

Dan

UPDATE: Should anyone else have the problem here is how I solved it.

  1. First cross compile GMP 3 times, setting the architectures to armv6. armv7, and i386 respectively. When building the arm versions add the flag -DNO_ASM to CPPFLAGS.

  2. Find LIPO the three .a files together

  3. Import .a file to XCode with gmp.g and gmpgxx.h.

  4. Done

like image 473
user1178964 Avatar asked Mar 01 '12 09:03

user1178964


1 Answers

As suggested by rob, I will answer my question and accept the answer. I'm new to this, so if there is an easier way forgive me, this is how I managed do it.

To build GMP for iphone you must build three the library from the command line three times. Build for the armv6, armv7, and i386 architectures. To ensure no problems in xcode make sure you add -DNO_ASM to CPPFLAGS. Once you have the three .a files, lipo them together into one library.

You can now add the library you created with lipo into xcode and include the headers, you now have GMP working for iphone development.

I hope this helps. I spent a couple days trying to figure this out.

like image 52
Dan Avatar answered Sep 17 '22 03:09

Dan