How to get the configuration script to search for a library

I am trying to write a configure.ac file in such a way that the resulting configure script searches for the library directory containing a given static library, eg. libsomething.a. How can i do this? I'm only checking one place at the moment:

AC_CHECK_FILE([/usr/local/lib/libsomething.a],[AC_SUBST(libsomething,"-L/usr/local/lib -lsomething")],[AC_SUBST(libcfitsio,'')])

      

But I want it to try to find it automatically. And if the library is not in one of the default locations, I would like to say that the library was not found and that a custom location can be specified with -use-something = path, as is usually done. So I also need to check if the -use-something = path is provided. I'm new to creating config files and the M4 documentation is not very easy to use, so appreciate any help.

Thank!

+2


source to share


2 answers


The best way to figure it out is to look at other autoconf macros that do something similar. Autoconf macros are a combination of Bourne shell script and M4 code, so they can literally solve any computable problem.



Here's a link to a macro I wrote for MySQL ++ that does this: mysql ++. m4 .

+2


source


It is not a configure job to find where libraries are installed. it only has to make sure they are available to the linker. If the user has installed them elsewhere, he knows how to call ./configure CPPFLAGS=-I/the/location/include LDFLAGS=-L/the/location/lib

for the tools to find the library (this is explained in the output --help

configure

and in the standard file INSTALL

).

Also macros --with-package

and --enable-package

should not be used to specify paths, unlike many third-party macros. The GNU coding standards explicitly prohibit this use:



Do not use the option --with

to specify a filename to search for specific files. It goes beyond what --with

options.

CPPFLAGS

and LDFLAGS

already here to solve this problem, so why rebuild and maintain a different mechanism?

+15


source







All Articles