views:

522

answers:

3

Hi

I generated a configure script with autoconf to build my project.

It works fine unless I don't have some needed library installed. Make returns error when lacking some files, but it should be actually checked by the configure script i think?

So my question is: How to modify an autoconf generated script to seek for dependencies and tell the user which libraries it lacks?

A: 

The way I've done this in the past is to write a trivial program that either pulls in a necessary header file, or links to a necessary library, and compile/link that in the configure script. If that fails, you emit a message stating that the requirement isn't met. I'd offer more details, but the code is on a drive that is no longer with us.

Harper Shelby
A: 

Yes, you want to perform the check at configure time. Stick code such as the following (thanks to Shlomi Fish) in your configure.ac:

if test "x$requires_libavl" = "xyes" ; then
    AC_CHECK_LIB(avl, avl_create, [], [
        echo "Error! You need to have libavl around."
        exit -1
        ])
fi

Note that if you have a pre-2.5 autoconf, you'll use configure.in instead.

Greg Bacon
If you have pre-2.5 autoconf, it's time to upgrade autoconf. 2.64 was just released!
William Pursell
Current autoconf best practice would code the above as:AS_IF([test "x$require_libavl" = "xyes"], [AC_CHECK_LIB([avl],[avl_create],[], [AC_MSG_ERROR([libavl required])])])
William Pursell
+2  A: 

Depends on the dependency, there is no generic solution.

There are AC_CHECK_LIB and AC_SEARCH_LIBS macros that may work for you if the libraries and headers are installed in standard locations.

Many packages nowadays support pkg-config or something similar which allows you to check for existence of libraries, and also can supply you the compiler and linker flags required.

With packages that do not work with AC macros and do not support pkg-config or similar, you'll probably have to write a ton of scripts yourself to find out whether the dependency is available and what compiler and linker options it requires. And even then it is hard to make it portable.

laalto
Thanks, these macros worked fine