[PATCH] configure.ac: Include math.h when checking for sqrt/cbrt

Daniel Stone daniel at fooishbar.org
Mon Jul 26 08:55:20 PDT 2010


On Mon, Jul 26, 2010 at 05:48:10PM +0200, Mark Kettenis wrote:
> > From: Daniel Stone <daniel at fooishbar.org>
> > Date: Mon, 26 Jul 2010 16:31:15 +0100
> > 
> > sqrt and cbrt are only defined in math.h, so we have to include that
> > when checking for them, lest we miss it, and then some other header
> > pulling in math.h causes build failures due to multiple definitions.
> 
> Eh, why?  AC_CHECK_LIB is supposed to check whether these symbols are
> available in the given library in a way that doesn't depend on a
> prototype for them being in scope.  So I don't see what you diff
> achieves, other than adding more clutter to the configure scripts.

Well, it does depend on a prototype for them being in scope.  It
constructs a basic int main(...) { foo(); } bit of source with
AC_LANG_CALL and then attempts to link it:

AC_DEFUN([AC_CHECK_LIB],
[m4_ifval([$3], , [AH_CHECK_LIB([$1])])dnl
AS_LITERAL_IF([$1],
              [AS_VAR_PUSHDEF([ac_Lib], [ac_cv_lib_$1_$2])],
              [AS_VAR_PUSHDEF([ac_Lib], [ac_cv_lib_$1''_$2])])dnl
AC_CACHE_CHECK([for $2 in -l$1], [ac_Lib],
[ac_check_lib_save_LIBS=$LIBS
LIBS="-l$1 $5 $LIBS"
AC_LINK_IFELSE([AC_LANG_CALL([], [$2])],
               [AS_VAR_SET([ac_Lib], [yes])],
               [AS_VAR_SET([ac_Lib], [no])])
LIBS=$ac_check_lib_save_LIBS])
AS_VAR_IF([ac_Lib], [yes],
      [m4_default([$3], [AC_DEFINE_UNQUOTED(AS_TR_CPP(HAVE_LIB$1))
  LIBS="-l$1 $LIBS"
])],
      [$4])
AS_VAR_POPDEF([ac_Lib])dnl
])# AC_CHECK_LIB

And it also solves the exact problem I described in my error message,
which was that AC_CHECK_LIB on cbrt failed, so we'd build our own
version of cbrt, which would cause the compile to fail because math.h
was dragged in, and you'd thus get a mixed static/non-static
declaration.  I didn't just write that for fun ...

Cheers,
Daniel
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://lists.x.org/archives/xorg-devel/attachments/20100726/3b88f0cc/attachment.pgp>


More information about the xorg-devel mailing list