如何使配置脚本检查依赖项

时间:2021-08-14 07:16:06

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

我用autoconf生成了一个配置脚本来构建我的项目。

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?

它工作正常,除非我没有安装一些必需的库。缺少某些文件时返回错误,但我认为应该通过configure脚本实际检查它?

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

所以我的问题是:如何修改autoconf生成的脚本以寻找依赖关系并告诉用户它缺少哪些库?

3 个解决方案

#1


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.

如果库和标头安装在标准位置,则可以使用AC_CHECK_LIB和AC_SEARCH_LIBS宏。

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.

现在许多软件包都支持pkg-config或类似软件,它允许您检查库是否存在,还可以为您提供所需的编译器和链接器标志。

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.

对于不支持AC宏且不支持pkg-config或类似软件包的软件包,您可能需要自己编写大量脚本来确定依赖项是否可用以及它需要哪些编译器和链接器选项。即使这样,也很难让它变得便携。

#2


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

是的,您想在配置时执行检查。在configure.ac中粘贴以下代码(感谢Shlomi Fish):

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.

请注意,如果您有2.5之前的autoconf,则将使用configure.in。

#3


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.

我过去这样做的方法是编写一个简单的程序,它可以引入必要的头文件,也可以链接到必要的库,然后在configure脚本中编译/链接它。如果失败,则会发出一条消息,指出未满足要求。我会提供更多详细信息,但代码位于不再与我们联系的驱动器上。

#1


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.

如果库和标头安装在标准位置,则可以使用AC_CHECK_LIB和AC_SEARCH_LIBS宏。

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.

现在许多软件包都支持pkg-config或类似软件,它允许您检查库是否存在,还可以为您提供所需的编译器和链接器标志。

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.

对于不支持AC宏且不支持pkg-config或类似软件包的软件包,您可能需要自己编写大量脚本来确定依赖项是否可用以及它需要哪些编译器和链接器选项。即使这样,也很难让它变得便携。

#2


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

是的,您想在配置时执行检查。在configure.ac中粘贴以下代码(感谢Shlomi Fish):

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.

请注意,如果您有2.5之前的autoconf,则将使用configure.in。

#3


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.

我过去这样做的方法是编写一个简单的程序,它可以引入必要的头文件,也可以链接到必要的库,然后在configure脚本中编译/链接它。如果失败,则会发出一条消息,指出未满足要求。我会提供更多详细信息,但代码位于不再与我们联系的驱动器上。