简体   繁体   English

使用自动工具获取所需的标题和库

[英]Using autotools to get needed headers and libraries

configure.ac can contains checks for headers and libraries: configure.ac可以包含对头文件和库的检查:

AC_CHECK_LIB(cap,cap_compare,[cap_libs="-lcap"])
AC_CHECK_HEADERS([sys/acl.h linux/netlink.h])

As there an autotools support just to simply get list of these files (their default location even if not presented or at least location to these which are presented): 由于存在自动工具支持,因此只需简单地获取这些文件的列表即可(即使未显示,也提供其默认位置,或者至少显示了这些文件的位置):

/usr/include/sys/acl.h
/lib/x86_64-linux-gnu/libcap.so.2

I'm trying to find/create tool which would from autotools input generated missing packages of a Linux distro. 我正在尝试查找/创建从autotools输入生成Linux发行版缺少的软件包的工具。

UPDATE I see I didn't express myself correctly and mislead you with incorrect statements. 更新我看到我没有正确表达自己,并以错误的陈述误导了您。 I'm one of the developers of LTP project . 我是LTP项目的开发人员之一。 I extended our autotools macros, so I have some knowledge how it works. 我扩展了我们的自动工具宏,因此我对它的工作原理有所了解。 As this project is aimed to be compiled from source code (there is not going to be a package in distros), I want to make it easy for users compiling it to provide it list of package dependencies for all major Linux distros. 由于该项目旨在从源代码进行编译(发行版中不会包含软件包),因此我希望用户可以轻松地对其进行编译,以提供所有主要Linux发行版的软件包依赖关系列表。

It would probably be easiest way just to maintain these dependencies manually. 手动维护这些依赖关系可能是最简单的方法。 But because we have these dependencies in form of autotools AC_CHECK_LIB() and AC_CHECK_HEADERS() macros, I'd like to use that. 但是因为我们以自动工具AC_CHECK_LIB()AC_CHECK_HEADERS()宏的形式具有这些依赖关系,所以我想使用它。 Somehow take input of autotools ( configure.ac and all m4/*.m4 ) and generate list of headers and directories: 以某种方式接受自动工具的输入( configure.ac和所有m4/*.m4 )并生成标题和目录列表:

sys/acl.h
linux/netlink.h
...

libcap.so
...

This list would be big help for me. 此列表对我有很大帮助。 This is what I want to know. 这就是我想知道的。

Of course, I can make this list manually or use regular expressions to parse it either from autotools or from source code, but it would be nice to get it from autotools out of the box. 当然,我可以手动创建此列表,也可以使用正则表达式从自动工具或源代码中解析它,但是最好从自动工具中获取它。

Ideas what to do with this list : I'd have another script with predefined include path and default library path ( /usr/include/ would be include path for most distros add eg /lib/x86_64-linux-gnu/ for Debian/Ubuntu or /usr/lib64 for openSUSE) which I put in front of headers and libraries. 如何处理此列表 :我将有另一个脚本,该脚本具有预定义的包含路径和默认库路径( /usr/include/将是大多数发行版的包含路径,例如为Debian / Ubuntu添加/lib/x86_64-linux-gnu//usr/lib64对于openSUSE)),我放在标题和库的前面。 IMHO pkg-config is not an option as it's *.pc config files are installed with dependencies, so it will not be available when the package I'm searching for isn't installed. IMHO pkg-config不是一个选项,因为它的*.pc配置文件带有依赖项,因此在未安装我要搜索的软件包时,它将不可用。

Then I'd search with this list for packages, using distribution tools which are able to search online (ie don't depend on package being installed, ie apt-file for Debian/Ubuntu, dnf , yum or zypper ) or search online ( https://packages.qa.debian.org/ , ...), but that's another topic. 然后,我将使用可以在线搜索的分发工具在此列表中搜索软件包(即不依赖于正在安装的软件包,即Debian / Ubuntu, dnfyumzypper apt-file )或在线搜索( https://packages.qa.debian.org/ ,...),但这是另一个主题。

I will assume here that you are not the owner of the configure.ac files. 我将在这里假定您不是configure.ac文件的所有者。 Unfortunately for you, I don't think that such a tool exists. 对于您来说不幸的是,我认为这样的工具不存在。

According to William Pursell's answer in this post , autotools is not a package manager, so it knows nothing about packages as such, as a Linux distro's package manager would. 根据William Pursell在本文中的回答,autotools不是软件包管理器,因此它对软件包本身一无所知,就像Linux发行版的软件包管理器一样。

pkg-config brings some notion of packages to autotools, but according to the post I linked earlier, the results it gives could be wrong, especially if you think about cross-compilation. pkg-config为自动工具带来了一些软件包概念,但是根据我之前链接的文章,它给出的结果可能是错误的,特别是如果您考虑交叉编译的话。

However, you could still use the pkg-config macros inside the configure.ac to try and identify which packages (known by your OS' package manager) are missing. 但是,您仍然可以使用configure.ac中的pkg-config宏来尝试确定哪些软件包(操作系统的软件包管理器已知)丢失。

Regarding the AC_CHECK_LIB and AC_CHECK_HEADERS , I believe you will have a hard time using them to generate absolute paths of the missing headers and libraries for the following reasons: 关于AC_CHECK_LIBAC_CHECK_HEADERS ,由于以下原因,我相信您将很难使用它们来生成缺少的标头和库的绝对路径:

  • The prefix of the location of header and library files depends on the distribution (the historical /usr/lib vs the newer /usr/lib/x86_64-linux seen on Ubuntu 16.04 for ex) 头文件和库文件位置的前缀取决于发行版(以前的/usr/lib与较新的/usr/lib/x86_64-linux在Ubuntu 16.04上可以看到)
  • The same thing is true inside a distribution itself ( /usr/lib vs /usr/local/lib ) 发行版内部也是如此( /usr/lib/usr/local/lib
  • Some OS package managers will not give you a list of files contained in a given package, unless the package is actually already installed on your system (this is the case of apt on Ubuntu 16.04) 某些OS软件包管理器不会提供给定软件包中包含的文件的列表,除非该软件包实际上已经安装在您的系统上(在Ubuntu 16.04上是apt的情况)
  • Packages containing a given library might not have the same name on distinct distros (I remember having this issue when using Fedora after Ubuntu, I couldn't find any of the packages I was used to) 包含给定库的软件包在不同发行版上可能不会具有相同的名称(我记得在Ubuntu之后使用Fedora时遇到此问题,我找不到我曾经使用过的任何软件包)

In short, I don't think such a tool exists (but could be wrong), and writing one could reveal quite complicated, and heavily tied to one particular OS/distribution. 简而言之,我认为不存在这样一种工具(但可能是错误的),编写一个工具可能会发现相当复杂,并且与一个特定的OS /发行版紧密相关。

As there an autotools support just to simply get list of these files (their default location even if not presented or at least location to these which are presented): 由于存在自动工具支持,因此只需简单地获取这些文件的列表即可(即使未显示,也提供其默认位置,或者至少显示了这些文件的位置):

You seem to have a misunderstanding about how Autoconf works. 您似乎对Autoconf的工作方式有误解。 It has no specific knowledge of where to locate headers or libraries, and certainly no concept of a default location. 它不知道在何处放置头文件或库,当然也没有默认位置的概念。 Rather, it uses the compiler and linker it previously discovered, and any flags that have been set in its standard variables, to check the presence of header files and libraries. 相反,它使用先前发现的编译器和链接器以及已在其标准变量中设置的所有标志来检查头文件和库的存在。

The compiler has a built-in search path for headers , and the linker similarly has a built-in search path for libraries . 编译器具有用于标头的内置搜索路径 ,而链接器类似地具有用于库的内置搜索路径 These may be augmented by -I , -L , and other flags that are in $CPPFLAGS , $CFLAGS , and $LDFLAGS , as appropriate, at the point where the checks are performed. 在执行检查时,可以通过-I-L$CPPFLAGS$CFLAGS$LDFLAGS其他标志来适当地增加这些标志。 The combination of these determines what locations are searched for any particular header or library, but again, not directly by the configure script itself. 这些因素的组合决定了在什么位置搜索任何特定的标头或库,但同样,它不是直接由configure脚本本身搜索的。

I'm trying to find/create tool which would from autotools input generated missing packages of a Linux distro. 我正在尝试查找/创建从autotools输入生成Linux发行版缺少的软件包的工具。

Well, you can certainly parse the Autoconf input file. 好吧,您当然可以解析Autoconf输入文件。 In fact, inasmuch as it is designed to be processed via m4 anyway, you could write a replacement set of m4 macros and configuration that serve up the details of the AC_CHECK_HEADER , AC_CHECK_LIB , etc. macros that are invoked. 实际上,由于无论如何都可以通过m4处理该宏,因此您可以编写一组替换的m4宏和配置,这些宏和配置提供了所调用的AC_CHECK_HEADERAC_CHECK_LIB等宏的详细信息。 You can that way get a pretty good idea of what libraries are required to build the package, but not of specific directories in which to find them. 您可以通过这种方式很好地了解构建软件包所需的库,而不是要在其中找到它们的特定目录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM