Node:Autoconf, Previous:Profiling, Up:GMP Basics



Autoconf

Autoconf based applications can easily check whether GMP is installed. The only thing to be noted is that GMP library symbols from version 3 onwards have prefixes like __gmpz. The following therefore would be a simple test,

AC_CHECK_LIB(gmp, __gmpz_init)

This just uses the default AC_CHECK_LIB actions for found or not found, but an application that must have GMP would want to generate an error if not found. For example,

AC_CHECK_LIB(gmp, __gmpz_init, , [AC_MSG_ERROR(
[GNU MP not found, see http://swox.com/gmp])])

If functions added in some particular version of GMP are required, then one of those can be used when checking. For example mpz_mul_si was added in GMP 3.1,

AC_CHECK_LIB(gmp, __gmpz_mul_si, , [AC_MSG_ERROR(
[GNU MP not found, or not 3.1 or up, see http://swox.com/gmp])])

An alternative would be to test the version number in gmp.h using say AC_EGREP_CPP. That would make it possible to test the exact version, if some particular sub-minor release is known to be necessary.

An application that can use either GMP 2 or 3 will need to test for __gmpz_init (GMP 3 and up) or mpz_init (GMP 2), and it's also worth checking for libgmp2 since Debian GNU/Linux systems used that name in the past. For example,

AC_CHECK_LIB(gmp, __gmpz_init, ,
  [AC_CHECK_LIB(gmp, mpz_init, ,
    [AC_CHECK_LIB(gmp2, mpz_init)])])

In general it's suggested that applications should simply demand a new enough GMP rather than trying to provide supplements for features not available in past versions.

Occasionally an application will need or want to know the size of a type at configuration or preprocessing time, not just with sizeof in the code. This can be done in the normal way with mp_limb_t etc, but GMP 4.0 or up is best for this, since prior versions needed certain -D defines on systems using a long long limb. The following would suit Autoconf 2.50 or up,

AC_CHECK_SIZEOF(mp_limb_t, , [#include <gmp.h>])

The optional mpfr functions are provided in a separate libmpfr.a, and this might be from GMP with --enable-mpfr or from MPFR installed separately. Either way libmpfr depends on libgmp, it doesn't stand alone. Currently only a static libmpfr.a will be available, not a shared library, since upward binary compatibility is not guaranteed.

AC_CHECK_LIB(mpfr, mpfr_add, , [AC_MSG_ERROR(
[Need MPFR either from GNU MP 4 or separate MPFR package.
See http://www.mpfr.org or http://swox.com/gmp])