
Bruno Haible wrote:
While compiling ppl-0.5 I had problems telling the configure script where my libgmp is installed. Just
--with-gmp-includes=/packages/gnu/include --with-gmp-lib=/packages/gnu/lib
wasn't enough, because
- the test program is linked without any -L option,
- the test program is linked without any -rpath option and then immediately run - which doesn't work when a program depends on shared libraries in nonstandard locations.
As a workaround, I had to use
LDFLAGS="-L/packages/gnu/lib -Wl,-rpath,/packages/gnu/lib" \ ./configure --prefix=/packages/gnu \ --with-gmp-includes=/packages/gnu/include --with-gmp-lib=/packages/gnu/lib
You could make this easier by using AC_LIB_LINKFLAGS(gmpxx, gmp) in your configure.ac file. The AC_LIB_LINKFLAGS macro is defined in gettext-0.12.1/autoconf-lib-link/m4/*.m4 from the GNU gettext-0.12.1 distribution.
Dear Bruno,
thank you very much for your suggestion. I have just downloaded gettext-0.12.1 and looking at AC_LIB_LINKFLAGS(gmpxx, gmp). I must say I was aware of the problem but could not find a portable solution (I know too little about shared libraries and libtool and so on and never find the time to fill this gap).
I agree the problem is very annoying: for example, if you happen to have one libgmp installed into a standard location, but you want to experiment with another version of libgmp, our --with-gmp-* options are of little help.
Would you be so kind to tell us more about the solution you suggest? Is adding AC_LIB_LINKFLAGS(gmpxx, gmp) to configure.ac really all what needs to be done? Shouldn't ac_check_gmp.m4 also be modified so that the directory specified with the option --with-gmp-dir can be taken into account? I also guess the position into configure.ac must be chosen carefully. Thanks again,
Roberto

Dear Roberto,
I must say I was aware of the problem but could not find a portable solution (I know too little about shared libraries and libtool and so on and never find the time to fill this gap).
AC_LIB_LINKFLAGS is meant to be this portable solution.
I agree the problem is very annoying: for example, if you happen to have one libgmp installed into a standard location, but you want to experiment with another version of libgmp, our --with-gmp-* options are of little help.
Would you be so kind to tell us more about the solution you suggest? Is adding AC_LIB_LINKFLAGS(gmpxx, gmp) to configure.ac really all what needs to be done? Shouldn't ac_check_gmp.m4 also be modified so that the directory specified with the option --with-gmp-dir can be taken into account?
When you do AC_LIB_LINKFLAGS(gmpxx, gmp), the configure script will automatically accept an option --with-libgmpxx-dir=<someDirectory> though which the user can specify where he instealled libgmpxx. In your current scheme, the equivalent options would be
--with-libgmpxx-includes=<someDirectory>/include \ --with-libgmpxx-lib=<someDirectory>/lib
The AC_LIB_LINKFLAGS macro also looks in $prefix, i.e. if the user has specified --prefix=<someDirectory> and does not specify --with-libgmpxx-dir, then the macros will look in $prefix/include and $prefix/lib. (Because it's quite common that prerequisites have already been installed with the same --prefix.)
In ac_check_gmp.m4 you also check whether the library is really present. I'd order the checks as follows:
1) [Optional] Call AC_LIB_LINKFLAGS(gmp). 2) Call AC_LIB_LINKFLAGS(gmpxx, gmp). This sets the variable LIBGMPXX and augments CPPFLAGS. If the library isn't found, LIBGMPXX will just be "-lgmpxx -lgmp". 3) Now temporarily augment LIBS ac_save_LIBS=$LIBS compile and run the test program LIBS=$ac_save_LIBS
And in the Makefiles, you add @LTLIBGMPXX@ to the link command line. That's it.
ac_check_gmp.m4 will then look similar the one below (untested).
I also guess the position into configure.ac must be chosen carefully.
Yes. Since the macro changes CPPFLAGS, it should come right after the detection of the C/C++ compiler, before other checks for include files and libraries.
And you will need a copy of config.rpath in your package. That's needed since runpath handling is so platform dependent.
Best, Bruno
========================================================================= dnl A function to check for the existence and usability of GMP. dnl Copyright (C) 2001-2003 Roberto Bagnara bagnara@cs.unipr.it dnl dnl This file is part of the Parma Polyhedra Library (PPL). dnl dnl The PPL is free software; you can redistribute it and/or modify it dnl under the terms of the GNU General Public License as published by the dnl Free Software Foundation; either version 2 of the License, or (at your dnl option) any later version. dnl dnl The PPL is distributed in the hope that it will be useful, but WITHOUT dnl ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or dnl FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License dnl for more details. dnl dnl You should have received a copy of the GNU General Public License dnl along with this program; if not, write to the Free Software dnl Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, dnl USA. dnl dnl For the most up-to-date information see the Parma Polyhedra Library dnl site: http://www.cs.unipr.it/ppl/ . dnl AC_DEFUN([AC_CHECK_GMP], [ dnl Check how to link with libgmp. AC_LIB_LINKFLAGS([gmp])
dnl Check how to link with libgmpxx. AC_LIB_LINKFLAGS([gmpxx], [gmp])
ac_save_LIBS="$LIBS" LIBS="$LIBS $LIBGMPXX" AC_LANG_PUSH(C++)
AC_MSG_CHECKING([for the GMP library]) AC_RUN_IFELSE([AC_LANG_SOURCE([[ #include <gmpxx.h>
using namespace std;
int main() { mpz_class pie("3141592653589793238462643383279502884"); exit(0); } ]])], AC_MSG_RESULT(yes) ac_cv_have_gmp=yes, AC_MSG_RESULT(no) ac_cv_have_gmp=no, AC_MSG_RESULT(no) ac_cv_have_gmp=no)
have_gmp=${ac_cv_have_gmp}
if test x"$ac_cv_have_gmp" = xyes then
AC_MSG_CHECKING([size of GMP mp_limb_t]) ac_cv_sizeof_mp_limb_t=none for size in 2 4 8 do AC_COMPILE_IFELSE([AC_LANG_SOURCE([[ #include <gmp.h>
int main() { switch (0) { case 0: case (sizeof(mp_limb_t) == $size): ; } return 0; } ]])], ac_cv_sizeof_mp_limb_t=$size; break) done AC_MSG_RESULT($size) AC_DEFINE_UNQUOTED(SIZEOF_MP_LIMB_T, $size, [Size of GMP's mp_limb_t.])
AC_MSG_CHECKING([whether GMP has been compiled with support for exceptions]) AC_RUN_IFELSE([AC_LANG_SOURCE([[ #include <gmpxx.h> #include <new> #include <cstddef> #include <cstdlib>
using namespace std;
static void* x_malloc(size_t) { throw bad_alloc(); }
static void* x_realloc(void*, size_t, size_t) { throw bad_alloc(); }
static void x_free(void*, size_t) { }
int main() { mp_set_memory_functions(x_malloc, x_realloc, x_free); try { mpz_class pie("3141592653589793238462643383279502884"); } catch (bad_alloc) { exit(0); } exit(1); } ]])], AC_MSG_RESULT(yes) ac_cv_gmp_supports_exceptions=yes, AC_MSG_RESULT(no) ac_cv_gmp_supports_exceptions=no, AC_MSG_RESULT(no) ac_cv_gmp_supports_exceptions=no)
gmp_supports_exceptions=${ac_cv_gmp_supports_exceptions} if test x"$gmp_supports_exceptions" = xyes then value=1 else value=0 fi AC_DEFINE_UNQUOTED(GMP_SUPPORTS_EXCEPTIONS, $value, [Not zero if GMP has been compiled with support for exceptions.])
fi
AC_LANG_POP(C++) LIBS="$ac_save_LIBS"
dnl We use libtool, therefore we take $LTLIBGMPXX, not $LIBGMPXX. gmp_library_option="$LTLIBGMPXX" ])

Bruno Haible wrote:
AC_LIB_LINKFLAGS is meant to be this portable solution.
Dear Bruno,
Thank you very much for explaining everything! I have made most of the necessary changes (I only need to go through our Makefile.am files). By the way, googling for AC_LIB_LINKFLAGS I have found a thread in the autoconf mailing list that suggests your macros were, around May 2002, about to be included in autoconf. What happened then? All the best,
Roberto

Hi Roberto,
By the way, googling for AC_LIB_LINKFLAGS I have found a thread in the autoconf mailing list that suggests your macros were, around May 2002, about to be included in autoconf. What happened then?
There were questions whether the macros better fit into autoconf or into libtool, a question that I could not resolve by myself. Until this can be resolved, they are a clearly separate part of the GNU gettext distribution, and also copied into 'gnulib', a general pool of sources and macros used in GNU packages.
Bruno

Bruno Haible wrote:
Yes. Since the macro changes CPPFLAGS, it should come right after the detection of the C/C++ compiler, before other checks for include files and libraries.
Dear Bruno,
I am sorry to bother you again, but I am missing something. As an aid to find those Makefile.am's where I need to add @LTLIBGMPXX@ to the link command line, I have removed GMP from the standard places and put it in a nonstandard place. Then I did
/home/roberto/ppl/ppl/configure --with-libgmp-prefix=/tmp/jank/ \ --with-libgmpxx-prefix=/tmp/jank/
In config.log I find
ac_cv_libgmp_cppflags= [...] ac_cv_libgmpxx_cppflags=-I/tmp/jank//include
which seems right for libgmpxx (but why isn't libgmp treated the same way?) Moreover all the generated Makefile's have
CPPFLAGS =
so that compilation fails miserably because gmpxx.h cannot be found. What am I missing? Cheers,
Roberto
P.S. To save your time, here is a checkout command you can copy&paste: cvs -d :pserver:anoncvs@cvs.cs.unipr.it:/cvs/ppl -z 9 checkout -P ppl

Roberto Bagnara wrote:
Moreover all the generated Makefile's have
CPPFLAGS =
so that compilation fails miserably because gmpxx.h cannot be found.
This is because two other .m4 macros reset CPPFLAGS to empty. This patch fixes it:
*** m4/ac_cxx_attribute_weak.m4 27 Aug 2003 16:22:47 -0000 1.1 --- m4/ac_cxx_attribute_weak.m4 28 Oct 2003 20:57:10 -0000 *************** *** 24,29 **** --- 24,31 ---- dnl AC_DEFUN([AC_CXX_SUPPORTS_ATTRIBUTE_WEAK], [ + ac_save_CPPFLAGS="$CPPFLAGS" + ac_save_LIBS="$LIBS" AC_LANG_PUSH(C++)
AC_MSG_CHECKING([whether the C++ compiler supports __attribute__ ((weak))]) *** m4/ac_cxx_flexible_arrays.m4 18 Apr 2003 19:37:18 -0000 1.6 --- m4/ac_cxx_flexible_arrays.m4 28 Oct 2003 20:57:10 -0000 *************** *** 23,28 **** --- 23,30 ---- dnl AC_DEFUN([AC_CXX_SUPPORTS_FLEXIBLE_ARRAYS], [ + ac_save_CPPFLAGS="$CPPFLAGS" + ac_save_LIBS="$LIBS" AC_LANG_PUSH(C++)
AC_MSG_CHECKING([whether the C++ compiler supports flexible arrays])
Also, with the current macro, it's apparently needed to specify both --with-libgmp-prefix=/tmp/jank and --with-libgmpxx-prefix=/tmp/jank. The following two patches let the user get away with just one of these.
The first one should be used if some of your programs need only libgmp but not libgmpxx. The second one can be used if all you ever link with is libgmpxx. (I've tested the second one in three configurations: with libgmp installed as shared libs, installed as static libs, and installed as static libs with .la files removed.)
*** m4/ac_check_gmp.m4 27 Oct 2003 21:11:02 -0000 1.14 --- m4/ac_check_gmp.m4 28 Oct 2003 21:07:10 -0000 *************** *** 23,28 **** --- 23,38 ---- dnl AC_DEFUN([AC_CHECK_GMP], [ + dnl Since libgmp and libgmpxx are usually installed in the same location, + dnl let the prefixes default from each other, + if test -n "$with_libgmpxx_prefix" && test -z "$with_libgmp_prefix"; then + with_libgmp_prefix="$with_libgmpxx_prefix" + else + if test -n "$with_libgmp_prefix" && test -z "$with_libgmpxx_prefix"; then + with_libgmpxx_prefix="$with_libgmp_prefix" + fi + fi + dnl Check how to link with libgmp. AC_LIB_LINKFLAGS([gmp])
*** m4/ac_check_gmp.m4 27 Oct 2003 21:11:02 -0000 1.14 --- m4/ac_check_gmp.m4 28 Oct 2003 21:20:35 -0000 *************** *** 24,30 **** AC_DEFUN([AC_CHECK_GMP], [ dnl Check how to link with libgmp. ! AC_LIB_LINKFLAGS([gmp])
dnl Check how to link with libgmpxx. AC_LIB_LINKFLAGS([gmpxx], [gmp]) --- 24,33 ---- AC_DEFUN([AC_CHECK_GMP], [ dnl Check how to link with libgmp. ! dnl This is not needed here, because 1. libgmp is always installed in the ! dnl same directory as libgmpxx (since they come from the same package), ! dnl 2. all programs in this package need libgmpxx, not only libgmp. ! dnl AC_LIB_LINKFLAGS([gmp])
dnl Check how to link with libgmpxx. AC_LIB_LINKFLAGS([gmpxx], [gmp])
Best regards, Bruno

Bruno Haible wrote:
Roberto Bagnara wrote:
Moreover all the generated Makefile's have
CPPFLAGS =
so that compilation fails miserably because gmpxx.h cannot be found.
This is because two other .m4 macros reset CPPFLAGS to empty. This patch fixes it:
[...]
Thanks Bruno!
Also, with the current macro, it's apparently needed to specify both --with-libgmp-prefix=/tmp/jank and --with-libgmpxx-prefix=/tmp/jank. The following two patches let the user get away with just one of these.
The first one should be used if some of your programs need only libgmp but not libgmpxx. The second one can be used if all you ever link with is libgmpxx. (I've tested the second one in three configurations: with libgmp installed as shared libs, installed as static libs, and installed as static libs with .la files removed.)
[...]
I think the first one is what we need. We test first for libgmp and then for libgmpxx so that we can detect the (quite common) situation whereby the user has compiled GMP without the --enable-cxx option. That way we are able to print a more informative error message. Thanks again! Cheers,
Roberto
participants (2)
-
Bruno Haible
-
Roberto Bagnara