How to make configure script check the dependencies

依然范特西╮ 提交于 2019-12-06 01:20:10

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.

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!