autoconf
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Specifying path to headers and libraries with configure


From: Steve M. Robbins
Subject: Re: Specifying path to headers and libraries with configure
Date: Fri, 5 Apr 2002 11:43:01 -0500
User-agent: Mutt/1.3.28i

On Fri, Apr 05, 2002 at 11:31:04AM +0100, Ollie Cook wrote:

> I have an application which links against librrd and I'd like my
> configure script to find where the rrd.h header and librrd.a library
> files are so that it can pass the paths to the compiler with -I and
> -L

A frequent question, if there ever was one.  The official answer is that
your users should read INSTALL and figure out how to set their CPPFLAGS
and LDFLAGS.

For convenience, I use the --with-build-path macro

  
http://www.gnu.org/software/ac-archive/Installed_Packages/smr_with_build_path.html



> However, I'm pretty sure that I'm now doing this right - and would appreciate
> some advice on the proper way to check for libraries and header files in 
> unusual
> directories (RRDtool keeps them in /usr/local/rrd-x.y.z/(include|lib)/).
> 
> If it's possible I'd also like the configure script to fail if it doesn't find
> the files in the specified path, rather than blindly accepting the extra paths
> and causing the compile to fail when 'make' is called.

After setting LDFLAGS and CPPFLAGS, you can then use use AC_CHECK_HEADER
and AC_CHECK_LIB to look for headers and libraries.  However, I find these
rather fragile: they don't work for C++ code, for one, and you aren't
guaranteed that the xpm.h header you found matches the library in
-lXpm.

I finally settled on the macro below, which you can use as follows:

    mni_REQUIRE_LIB(m,[#include <math.h>],[double x = sqrt(3.);])
    mni_REQUIRE_LIB(netcdf,[#include <netcdf.h>],[int i = ncopen("",0);])

    AC_LANG_PUSH(C++)
    mni_REQUIRE_LIB(qt,[#include <qapplication.h>],[QString str;])
    AC_LANG_POP

All the libraries are put on the $LIBS variable, so you don't need to
do anything special in your Makefile.am for linking.  If library A
requires library B, check for B first, then A.


dnl @synopsis mni_REQUIRE_LIB(LIBRARY,INCLUDES,BODY)
dnl
dnl @version $Id: mni_REQUIRE_LIB.m4,v 1.1 2001/08/20 16:51:50 stever Exp $
dnl @author Steve M. Robbins <address@hidden>


AC_DEFUN([mni_REQUIRE_LIB],
[
  AC_MSG_CHECKING([for library $1])
  LIBS="-l$1 $LIBS"
  AC_TRY_LINK([$2],[$3],[mni_result=yes],[mni_result=no])
  AC_MSG_RESULT([$mni_result])
  if test "$mni_result" = "no"; then
    AC_MSG_ERROR([cannot find required library $1])
  fi
])


-Steve


-- 
by Rocket to the Moon,
by Airplane to the Rocket,
by Taxi to the Airport,
by Frontdoor to the Taxi,
by throwing back the blanket and laying down the legs ...
- They Might Be Giants




reply via email to

[Prev in Thread] Current Thread [Next in Thread]