[pkg-boost-devel] [Boost C++ Libraries] #1094: Finding the correct library to link (feature request for pkg-config support)h

Boost C++ Libraries noreply at lists.boost.org
Mon Jul 16 17:42:37 UTC 2007

#1094: Finding the correct library to link (feature  request for pkg-config
 Reporter:  rleigh at debian.org  |        Type:  Bugs                             
   Status:  new                |   Milestone:  To Be Determined                 
Component:  None               |     Version:                                   
 Severity:  Problem            |    Keywords:  pkg-config linking library naming
 This bug report is a feature request for the addition of pkg-config
 support to Boost, in order to provide a simple, reliable, platform-
 independent mechanism for discovering if the Boost libraries are
 installed, what they are called, where they are installed, and how to link
 with them.  This is currently not possible to achieve.  A detailed
 rationale and an example for how to implement this follow.

 I make use of several Boost libraries in my schroot program

 This project, like many, utilises GNU Autoconf and Automake for its
 build system.  I need to determine how to link with the Boost
 libraries in order to build the programs in the project.  This is an
 issue for many projects which want to link with a Boost library.  Note
 that calling bjam is not a possibility here; it may not be installed, and
 most projects are not using bjam, especially if boost is just one of many
 libraries being used.

 To illustrate my problem:

  ls -l /usr/lib/libboost_regex-*.so /usr/lib/libboost_program_options-*.so
 lrwxrwxrwx 1 root root 45 2007-07-08 11:48 /usr/lib/
 libboost_program_options-gcc41-1_34.so -> libboost_program_options-gcc41-
 lrwxrwxrwx 1 root root 48 2007-07-08 11:48 /usr/lib/
 libboost_program_options-gcc41-mt-1_34.so -> libboost_program_options-
 lrwxrwxrwx 1 root root 41 2007-07-08 11:48 /usr/lib/
 libboost_program_options-mt.so -> libboost_program_options-gcc41-mt-
 lrwxrwxrwx 1 root root 38 2007-07-08 11:48 /usr/lib/
 libboost_program_options-st.so -> libboost_program_options-gcc41-1_34.so
 lrwxrwxrwx 1 root root 35 2007-07-08 11:47 /usr/lib/libboost_regex-gcc41-
 1_34.so -> libboost_regex-gcc41-1_34.so.1.34.0
 lrwxrwxrwx 1 root root 38 2007-07-08 11:47 /usr/lib/libboost_regex-gcc41-
 mt-1_34.so -> libboost_regex-gcc41-mt-1_34.so.1.34.0
 lrwxrwxrwx 1 root root 31 2007-07-08 11:47 /usr/lib/libboost_regex-mt.so
 -> libboost_regex-gcc41-mt-1_34.so
 lrwxrwxrwx 1 root root 28 2007-07-08 11:47 /usr/lib/libboost_regex-st.so
 -> libboost_regex-gcc41-1_34.so

 Unlike every other library on my system, the Boost libraries have the
 compiler (gcc41) and threading model (mt|st) and so on embedded *in
 the library name*.  This makes it impossible to discover in an
 automatic fashion.  Since my project is free software anyone can download
 and build, I don't know what the compiler/toolchain will be, let alone
 what abbreviation Boost has chosen for it.  I expect that Autoconf
 will set up such things appropriately; my code is relatively compiler-
 agnostic, but I can't predict the Boost library names without help.

 The only means I have are the libboost_program_options-mt.so,
 libboost_program_options-st.so (and so on for all the libraries)
 symbolic links which the Debian maintainer has helpfully provided.
 However, these are not portable, and are so not a good solution.  They
 are, however, the only available solution at the moment.

 To further show the problem I am having, this is part of my
 configure.ac Autoconf template:


 AC_CHECK_HEADERS([boost/shared_ptr.hpp],, [
   if test $ac_cv_header_tr1_memory = yes; then
     AC_MSG_ERROR([Boost.shared_ptr (Boost C++ Libraries) is not installed,
 but is required by schroot])


 AC_CHECK_HEADERS([boost/tuple/tuple.hpp],, [
   if test $ac_cv_header_tr1_memory = yes; then
     AC_MSG_ERROR([Boost.Tuple (Boost C++ Libraries) is not installed, but
 is required by schroot])

 AC_CHECK_HEADERS([boost/format.hpp],, [AC_MSG_ERROR([Boost.Format (Boost
 C++ Libraries) is not installed, but is required by schroot])])
 [AC_MSG_ERROR([Boost.Program_options (Boost C++ Libraries) is not
 installed, but is required by schroot])])
 AC_CHECK_HEADERS([boost/type_traits.hpp],, [AC_MSG_ERROR([Boost.TypeTraits
 (Boost C++ Libraries) is not installed, but is required by schroot])])

 AC_MSG_CHECKING([for boost::program_options::variables_map in
 LDFLAGS="${LDFLAGS} -lboost_program_options-st"
 AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <boost/program_options.hpp>],
 [boost::program_options::variables_map::variables_map dummy()])],
                 BOOST_LIBS="${BOOST_LIBS} -lboost_program_options-st"],
                 AC_MSG_FAILURE([libboost_program_options (Boost C++
 Libraries) is not installed, but is required by schroot])])

 boost::program_options::options_description::options() in
 LDFLAGS="${LDFLAGS} -lboost_program_options-st"
 AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <boost/program_options.hpp>],
 [boost::program_options::options_description testgrp("test group");
                                 bool notused = testgrp.options().empty();
 boost::program_options::options_description::options() is not available])

 AC_MSG_CHECKING([for boost::regex in -lboost_regex-st])
 LDFLAGS="${LDFLAGS} -lboost_regex-st"
 AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <boost/regex.hpp>],
                 BOOST_LIBS="${BOOST_LIBS} -lboost_regex-st"],
                 AC_MSG_FAILURE([libboost_regex (Boost C++ Libraries) is
 not installed, but is required by schroot])])



 As you can see, that's quite a bit of complexity.  It also includes
 code to work around a backwards compatibility issue in
 Boost.Program_options.  However, it needs to know the library name in
 order to link the test code, and I'm still needing to use a
 non-standard name in order to do that.

 It would be great if Boost would provide a mechanism to allow such
 discovery.  Such a mechanism already exists, and is called
 "pkg-config".  By installing a small file in LIBDIR/pkgconfig for each
 Boost library, the pkg-config tool or PKG_CHECK_MODULES Autoconf macro
 may be used to query this information.  As an example:

 ---- boost-regex-mt.pc ----

 Name: boost-regex-mt
 Description: Boost C++ Regular Expression Library (multi-threaded)
 Version: 1.34.0
 Libs: -L${libdir} -lboost_regex-gcc41-mt-1_34
 Libs.private: -licui18n -licuuc -lrt -lm
 Cflags: -I${includedir} -pthread
 ---- boost-regex-mt.pc ----

 You can generate this from a template:

 ---- boost-regex-mt.pc.in ----

 Name: boost-regex-mt
 Description: Boost Regular Expression Library (multi-threaded)
 Version: VERSION
 Libs: -L${libdir} LIBRARY_NAME
 Libs.private: LIBRARY_DEPENDENCIES [for static linking]
 Cflags: -I${includedir} THREAD_OPTIONS_FOR_COMPILER
 ---- boost-regex-mt.pc.in ----

 where the capitalised names are where you would substitute in the
 system- and compiler-specific options.  It looks like bjam could
 probably make this a single rule all libraries could make use of.

 For such a setup, all that configure script above could be mostly
 reduced to


 I don't know how bjam works, but I do this with Autoconf as a file
 generated by config.status, but it could also be generated by make
 with a simple sed command.  I guess you could do the bjam equivalent,
 whatever that might be.  I have had a look at the sources to try to
 implement this, but I am afraid I lack the bjam expertise to do it.

 You may find much more detailed discussion of these issues at


 Some of these are due to Debian-specific issues (a change to the
 symlink name), but the root cause is the inability to identify the
 Boost library names in an automated fashion.


   .''`.  Roger Leigh
  : :' :  Debian GNU/Linux             http://people.debian.org/~rleigh/
  `. `'   Printing on GNU/Linux?       http://gutenprint.sourceforge.net/
    `-    GPG Public Key: 0x25BFB848   Please GPG sign your mail.

Ticket URL: <http://svn.boost.org/trac/boost/ticket/1094>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

More information about the pkg-boost-devel mailing list