3

I am using autotools for a project. I wanted to understand the best practice when it comes to checking for the existence of libraries?

I tried using PKG_CHECK_MODULES, but unfortunately many of the libraries I am using don't show up in pkg-config --list-all (even after running ldconfig).

The alternative is to use AC_CHECK_LIB, but that requiress me to specify an example function from each library that I need to test for.

usr1234567
  • 21,601
  • 16
  • 108
  • 128
Anirudh
  • 239
  • 3
  • 11

2 Answers2

2

Whenever a third party software supports pkg-config, use it. If the third party software has no pkg-config support, you have to write your own check.

Unless Autoconf already provides a test or you can copy a test from an other open source project.

usr1234567
  • 21,601
  • 16
  • 108
  • 128
2

I'll have to disagree with the accepted answer. (See PKG_CHECK_MODULES considered harmful?) PKG_CHECK_MODULES was popular for a time many years ago, but was never considered good practice by a majority of developers on the autoconf mailing lists. The autotools are not a package management system, and PKG_CHECK_MODULES seems to be an attempt to shoe-horn package management functionality in. If a package uses PKG_CHECK_MODULES, the configure script must still invoke AC_CHECK_LIB to validate the information returned by pkg-config or risk a build failure. Further, if a user invokes configure with LDFLAGS=-l/p/a/t/h/, they should reliably expect the build to use /p/a/t/h/liboo.so rather than using some other location, but PKG_CHECK_MODULES requires that the user either override PKG_CONFIG_PATH or otherwise alter the response from pkg-config in order to override a library search path.

Community
  • 1
  • 1
William Pursell
  • 204,365
  • 48
  • 270
  • 300
  • 1
    Fair enough. Is the right solution then to always use AC_CHECK_LIB? It doesn't work very well for C++ functions though (http://nerdland.net/2009/07/detecting-c-libraries-with-autotools/). Besides, pkg-config --libs (when it does work) gives you secondary library dependencies as well. – Anirudh Apr 16 '15 at 16:06