Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to include Boost in GNU Autotools project?

My project compiles using GNU autotools (aclocal && autoconf && ./configure && make). I'd like to use Boost, and I'd like for other people to be able to compile it as well.

  1. Should I put Boost in my project's dir, or rely on the system's Boost?
  2. How should I tell autotools to use Boost? I've Googled and found many m4 files that claim to do this - but where should I put those m4 files? I can stash one in my /usr/share/aclocal dir, but that doesn't help someone else who wants to compile the project using ./configure && make.
like image 245
SRobertJames Avatar asked Aug 16 '13 19:08

SRobertJames


2 Answers

The Archive has AX_BOOST_*.

I switched to boost.m4 for some time, but it is so painfully slow I could edit a Makefile with the full Boost path by hand in vim before boost.m4 finished testing for the second library.

I went back to the Archive and was happy to learn the boost macros are being actively maintained again; then I proceeded to purge boost.m4 from every one of my projects.

Relevant excerpts from a use case (assuming the ax_boost_*.m4 files are in subdir m4):

./bootstrap

aclocal -I m4 --install
...

./configure.ac

...
AC_CONFIG_MACRO_DIR([m4])
...
AX_BOOST_BASE([1.48],, [AC_MSG_ERROR([libfoo needs Boost, but it was not found in your system])])
AX_BOOST_SYSTEM
AX_BOOST_FILESYSTEM
...

./Makefile.am

ACLOCAL_AMFLAGS = -I m4
EXTRA_DIST = bootstrap ...
SUBDIRS = ... src ...
...

./src/Makefile.am

AM_CPPFLAGS = \
    ... \
    $(BOOST_CPPFLAGS) \
    ...

...

AM_LDFLAGS = ... \
    $(BOOST_LDFLAGS)

...

lib_LTLIBRARIES = libFoo.la

...

libFoo_la_LIBADD = \
    ... \
    $(BOOST_FILESYSTEM_LIB) \
    $(BOOST_SYSTEM_LIB) \
    ...
like image 163
DanielKO Avatar answered Nov 01 '22 02:11

DanielKO


There's an excellent boost.m4 macro that you can include in your project in the m4 subdirectory. These macros are located with AC_CONFIG_MACRO_DIR([m4]) in configure.ac.

Add ACLOCAL_AMFLAGS = -I m4 --install to the top-level Makefile.am, used by automake.

Here's why it's such a good macro:

BOOST_REQUIRE([1.54],[ACTION-IF-NOT-FOUND])

This will define BOOST_CPPFLAGS which you can add to CPPFLAGS, use in an AC_SUBST, etc.

For individual Boost components, it's possible to specify debug builds, static builds, etc. But the (typically) multi-threaded, dynamic libraries are best, e.g.,

BOOST_FILESYSTEM([mt])

will define BOOST_FILESYSTEM_LIBS and BOOST_FILESYSTEM_LDFLAGS. As another bonus, if the library relies on, say, Boost.System, then these library dependencies are automatically added to the LIBS, LDFLAGS, etc.


You should just specify that a Boost installation is required rather than trying to distribute it. It's easily built and installed from source, or from precompiled packages. The former takes a long time, but it's best to have an 'optimized' build on the system. There's a lot of software that can make use of a (robust and optimized) Boost implementation.

Then use the BOOST_REQUIRE error message if there's no acceptable version available.

like image 2
Brett Hale Avatar answered Nov 01 '22 02:11

Brett Hale