Building gmp 32-bit and 64-bit intel binary on Mac OS X 10.6.4

Elvis Dowson elvis.dowson at mac.com
Mon Sep 13 23:54:28 CEST 2010


Hi,
	Here is the full solution and the modifications for gmp.h (credit goes to Wesley W. Terpstra).

-------------- next part --------------
A non-text attachment was scrubbed...
Name: PDCheckboxChecked.png
Type: image/png
Size: 685 bytes
Desc: not available
URL: <http://gmplib.org/list-archives/gmp-discuss/attachments/20100914/3409b326/attachment.png>
-------------- next part --------------
 Install GNU MP multiple precision arithmetic library.

Step 01: Download gmp-5.0.1 from 

ftp://ftp.gmplib.org/pub/gmp-5.0.1/gmp-5.0.1.tar.bz2

$ cd gmp-5.0.1
$ make distclean
$ mkdir build-i386
$ cd build-i386

The GNU MP library can only be compiled on Mac OS X using gcc-4.2.1, so we will need to configure it using gcc-4.2.1 as follows:

$ ../configure CC='/usr/bin/gcc-4.2' CPP='/usr/bin/cpp-4.2' CXX='/usr/bin/g++-4.2' CXXCPP='/usr/bin/cpp-4.2' CFLAGS='-arch i386' CPPFLAGS='-arch i386' CXXFLAGS='-arch i386 ' LDFLAGS='-arch i386' ABI=32 --prefix=/Users/elvis/Tool/gmp-5.0.1/install-i386
$ make -j 6
$ make install
$ cd ..

This will install the files into gmp-5.0.1/install-i386

$ mkdir build-x86_64
$ cd build-x86_64
$ ../configure CC='/usr/bin/gcc-4.2' CPP='/usr/bin/cpp-4.2' CXX='/usr/bin/g++-4.2' CXXCPP='/usr/bin/cpp-4.2' CFLAGS='-arch x86_64' CPPFLAGS='-arch x86_64' CXXFLAGS='-arch x86_64' LDFLAGS='-arch x86_64' ABI=64 --prefix=/Users/elvis/Tool/gmp-5.0.1/install-x86_64
$ make -j 6
$ make install
$ cd ..

This will install the files into gmp-5.0.1/install-x86_64

Step 02: Create the universal binary using lipo.

$ mkdir -p install-universal/lib
$ lipo -create install-i386/lib/libgmp.10.dylib -create install-x86_64/lib/libgmp.10.dylib -output install-universal/lib/libgmp.10.dylib
$ lipo -create install-i386/lib/libgmp.a -create install-x86_64/lib/libgmp.a -output install-universal/lib/libgmp.a

Step 03: Modify the automatically generated libtool library file.

$ cp install-x86_64/lib/libgmp.la install-universal/lib/libgmp.la

Edit install-universal/lib/libgmp.la and modify the libdir entry as follows:

libdir='/usr/local/lib'


Step 04: Modify the header file for 32-bit and 64-bit operation. 

$ mkdir -p install-universal/include
$ cp install-x86_64/include/gmp.h install-universal/include/gmp.h

Edit install-universal/include/gmp.h and modify it as follows:

#if defined(__i386__)
#define __GMP_HAVE_HOST_CPU_FAMILY_power   0
#define __GMP_HAVE_HOST_CPU_FAMILY_powerpc 0
#define GMP_LIMB_BITS                      32
#define GMP_NAIL_BITS                      0
#elif defined(__x86_64__)
#define __GMP_HAVE_HOST_CPU_FAMILY_power   0
#define __GMP_HAVE_HOST_CPU_FAMILY_powerpc 0
#define GMP_LIMB_BITS                      64
#define GMP_NAIL_BITS                      0
#elif defined(__ppc__)
#define __GMP_HAVE_HOST_CPU_FAMILY_power   0
#define __GMP_HAVE_HOST_CPU_FAMILY_powerpc 1
#define GMP_LIMB_BITS                      32
#define GMP_NAIL_BITS                      0
#elif defined(__powerpc64__)
#define __GMP_HAVE_HOST_CPU_FAMILY_power   0
#define __GMP_HAVE_HOST_CPU_FAMILY_powerpc 1
#define GMP_LIMB_BITS                      64
#define GMP_NAIL_BITS                      0
#else
#error Unsupported architecture
#endif

Step 05: Install the library.

$ sudo cp install-universal/lib/libgmp.10.dylib /usr/local/lib
$ sudo cp install-universal/lib/libgmp.a /usr/local/lib
$ sudo cp install-universal/lib/libgmp.la /usr/local/lib
$ cd /usr/local/lib
$ sudo ln -s libgmp.10.dylib libgmp.dylib

$ sudo cp install-x86_64/include/gmp.h /usr/local/include

Best regards,

Elvis Dowson




More information about the gmp-discuss mailing list