I am an autotools newb and I have difficulties figuring out howto easily link a specific library into one of the configured targets.
I have a source package that I want to build the usual way: ./configure && make && make install
Unfortunately one of the cpps has a missing reference to another library. Compiling it by hand (adjusting the commandline) works. But I would rather "patch" the compile script. Where is the standard place to edit linking references?
undefined reference to `boost::system::get_system_category()
That is my error message btw.
To create a configure script with Autoconf, you need to write an Autoconf input file configure.ac (or configure.in ) and run autoconf on it. If you write your own feature tests to supplement those that come with Autoconf, you might also write files called aclocal. m4 and acsite. m4 .
In software development, GNU Automake is a programming tool to automate parts of the compilation process. It eases usual compilation problems. For example, it points to needed dependencies. It automatically generates one or more Makefile.in from files called Makefile.am.
Autoconf essentially runs the preprocessor on your script to produce a portable shell script which will perform all the requisite tests, produce handy log files, preprocess template files, for example to generate Makefile from Makefile.in and and take a standard set of command line arguments.
You need to add the relevant -l
flag to AM_LDFLAGS
in Makefile.am
; e.g.:
AM_LDFLAGS = -lboost_system-mt
Note that Boost libraries generally end in a suffix—a sequence of letters that indicates the build configuration. In the above example, the suffix is -mt
. This could be different in your installation (though the -mt
variant is commonly available on POSIXy systems, IME).
I do something like this:
AM_LDFLAGS = -lboost_system$(BOOST_LIB_SUFFIX)
BOOST_LIB_SUFFIX
is a precious variable (see AC_ARG_VAR
) that defaults to -mt
.
Use ax_cxx_check_lib.m4
because boost_system does not have any extern "C" symbols (unmangled names) that can be checked with AC_CHECK_LIB
:
http://ac-archive.sourceforge.net/guidod/ax_cxx_check_lib.m4
Download the file above and name it acinclude.m4
, and put it in the m4
folder in your project root.
In configure.ac
:
AC_LANG_PUSH([C++])
AX_CXX_CHECK_LIB([boost_system-mt],[boost::system::generic_category()],[BOOST_LIB_SUFFIX="-mt"],[BOOST_LIB_SUFFIX=""])
AC_LANG_POP([C++])
AC_SUBST(BOOST_LIB_SUFFIX)
In Makefile.am
:
[artifact_name]_LDFLAGS = -lboost_system@BOOST_LIB_SUFFIX@
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With