[英]What is the difference between a lib and an module with autoconf
I have to check that certain libraries (libm, libdl) are present in order to compile my library. 我必须检查某些库(libm,libdl)是否存在才能编译我的库。
In my configure.ac template file, there is PKG_CHECK_MODULES
macros and PKG_CHECK_LIB
macros. 在我的configure.ac模板文件中,有
PKG_CHECK_MODULES
宏和PKG_CHECK_LIB
宏。
I don't understand which one to use and how? 我不知道该使用哪个以及如何使用?
The PKG_CHECK_MODULES
seems the most global one because it checks if a whole library is present and PKG_CHECK_LIB
checks only if one function is accessible… But when I do PKG_CHECK_MODULES([LIBM],[libm],[],[exit -1])
, it exists and I don't understand why. PKG_CHECK_MODULES
似乎是最全局的,因为它检查是否存在整个库,而PKG_CHECK_LIB
仅检查是否可以访问一个函数……但是当我执行PKG_CHECK_MODULES([LIBM],[libm],[],[exit -1])
,它存在,我不明白为什么。
I think I'm misunderstanding some concepts. 我想我误解了一些概念。 Maybe someone could lead me to good references.
也许有人可以引导我参考。
PKG_CHECK_MODULES
is for integrating with packages that have pkg-config metadata. PKG_CHECK_MODULES
用于与具有pkg-config元数据的软件包集成。 This metadata is typically stored in a file called foo.pc
(for package foo
) in someplace like /usr/share/pkgconfig
. 该元数据通常存储在
/usr/share/pkgconfig
类的名为foo.pc
(用于foo
包)的文件中。 This file will say where foo
and its associated files (header files, libraries, executables, data, etc.) have actually been installed. 该文件将说明
foo
及其相关文件(头文件,库,可执行文件,数据等)的实际安装位置。
However, most packages don't use the pkg-config
system, including the standard C library which is where libm
and libdl
are. 但是,大多数软件包都不使用
pkg-config
系统,包括标准C库,即libm
和libdl
所在的库。 So you'll need to test for them using AC_CHECK_LIB
. 因此,您需要使用
AC_CHECK_LIB
对其进行AC_CHECK_LIB
。
You seem to be confused, so I'll go on a bit of a tangent here: 您似乎很困惑,所以在这里我要讲一点切线:
Once upon a time, there was X11; 从前,有X11; there were many incompatible installations of X11.
X11的安装不兼容。 To write code that would compile against each variant, people would write crazy autoconf macros to try to figure out automatically what libraries to list before, what libraries to list after, and what extra flags were needed in between.
为了编写可针对每个变体进行编译的代码,人们会编写疯狂的autoconf宏,以尝试自动找出之前要列出的库,之后要列出的库以及之间需要额外的标志。 (see
AC_PATH_X
, AC_PATH_XTRA
). (请参阅
AC_PATH_X
和AC_PATH_XTRA
)。
Some people tried more sensible approaches, and wrote shell scripts to install along the libraries; 有些人尝试了更明智的方法,并编写了一些shell脚本以在这些库中安装; so you would just call them and they would give you all the magic flags needed for that specific libraries.
因此,您只需调用它们,它们就会为您提供该特定库所需的所有魔术标记。 (see
sdl-config
, wx-config
, freetype-config
, motif-config
, etc) (请参阅
sdl-config
, wx-config
, freetype-config
, motif-config
等)
Then the folks from freedesktop.org decided it was a chore for everyone to maintain those scripts that did essentially the same thing, so they wrote a tool (pkg-config) that would work like all those *-config
scripts, and would not require a shell to run (yay for Windows users). 然后,来自freedesktop.org的人们认为,维护那些执行相同操作的脚本对于每个人来说都是一件繁琐的事情,因此他们编写了一个工具(pkg-config),该工具可以像所有
*-config
脚本一样工作,并且不需要要运行的外壳程序(适用于Windows用户)。 All the library authors need to do is to write the metadata in the *.pc
files, and install them along the libraries. 库作者需要做的就是将元数据写入
*.pc
文件,然后将它们安装在库中。
Regarding autoconf, it has low-level ways to poke around the system to find out about the libraries: AC_CHECK_HEADERS
, to see if the headers are present and usable, and AC_CHECK_LIB
, to see if it's possible to link against them. 关于autoconf,它具有在系统中查找
AC_CHECK_HEADERS
库的低级方法: AC_CHECK_HEADERS
,查看标头是否存在和可用,以及AC_CHECK_LIB
,查看是否可以针对它们进行链接。
The pkg-config tool comes with convenience macros for autoconf, mainly PKG_CHECK_MODULES
, which instead of poking around, it simply looks for the metadata the library might have installed. pkg-config工具带有用于autoconf的便捷宏,主要是
PKG_CHECK_MODULES
,它不是在四处寻找,而只是在寻找库可能已安装的元数据。
Regarding libm, libdl, as ldav1s said, they are part of the system; 关于ldav1所说的libm,libdl,它们是系统的一部分。 some systems need explicit link against libm (which provides math functions) and/or libdl (which provides functions for dynamically loading shared objects).
一些系统需要针对libm(提供数学函数)和/或libdl(提供动态加载共享对象的函数)的显式链接。 Often other tools, like gcc or libtool, take care of linking against them.
通常,其他工具(例如gcc或libtool)会负责与它们链接。 Unfortunately they don't come with meta-data for pkg-config, so if you have to find them manually, you'll have to poke around with the old
AC_CHECK_HEADERS
and AC_CHECK_LIB
macros to find them. 不幸的是,它们没有pkg-config的元数据,因此,如果您必须手动查找它们,则必须使用旧的
AC_CHECK_HEADERS
和AC_CHECK_LIB
宏来查找它们。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.