6

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

Community
  • 1
  • 1
user1178964
  • 85
  • 2
  • 6
  • I figured it out. I now have a working GMP library that works for the simulator(i386) and devices (armv6 & armv7). I wonder if I can use the armv6/7 part of Android development with the NDK. Now to write an objective c wrapper to make it play nice with NSString. – user1178964 Mar 01 '12 at 22:00
  • 4
    You can (and should) post an answer to your own question, and accept it. – rob mayoff Mar 02 '12 at 00:51

2 Answers2

6

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.

Dan
  • 96
  • 3
  • Thanks for the answer but could you provide a link so the donwloadable libraries? I cannot seam to get it working. Thanks! – doozMen Jan 29 '13 at 19:39
  • How did you get the cross-compile step to work for any of the architectures? When I try it, I get the same problem you originally reported. – hrabinowitz Mar 20 '17 at 22:33
  • When trying to cross-compile, I always get stuck with this config error: "configure: error: Oops, mp_limb_t is 64 bits, but the assembler code in this configuration expects 32 bits." – hrabinowitz Mar 20 '17 at 22:40
0

You may be inspired by this bash script for OpenSSL and adapt it for GMP. It uses the standard configure script and substitutes CC and CFLAGS using perl.

yageek
  • 4,115
  • 3
  • 30
  • 48