I am trying to set up my project to use the autotools build system for distribution. However, I am having a problem when it comes to including a few extra libraries.
My code depends on a few libraries:
One I wrote (I'll call libfoo)
One that is third party (I'll call libbar)
Eigen3 (which is just header files)
These are all already compiled and installed in my $HOME directory. I do not need to build them as part of this project.
The flags I need are
-std=c++11 (Got this taken care of)
and
-I/path/to/include/libfoo (or libbar, or Eigen3)
and
-L/path/to/lib/ (Where libfoo and libbar reside)
and
-lfoo
to compile and link against libfoo and libbar
The problem is that I want to set up checks for the presence of libfoo and libbar and their headers (I have a check for Eigen3 set up already). The issue is that macros like AC_CHECK_HEADERS and AC_CHECK_LIB don't seem to want to include the required CPPFLAGS or LDFLAGS, no matter how I try to define them, so the configuration step fails.
AC_LANG_PUSH([C++])
AC_CHECK_HEADERS([libfoo/foo.h], , [echo "Did not find libfoo headers"; exit -1])
AC_LANG_POP([C++])
Reading config.log shows that configure is trying to compile against the header using
g++ -std=c++11 (other flags...)
but is failing due to the missing flags above (The error is "Cannot find Eigen3/dense", or similar, indicating the missing -I flag)
I'm a newbie to autotools, so I may be missing something obvious, but I've read through a good amount of help and manuals and have so far failed to figure out what I need to do to set this up.
Related: I want the user to be able to manually specify the location of libfoo and libbar via --with-libfoo-include (etc) if needed, so I also need to be able to specify where configure detects these libraries. How can this be done?
All you need to do are:
For
-std=c++11 (Got this taken care of)
is good to use ax_cxx_compile_stdcxx_11.m4
To use it, you need to download it from the above link and set it in $(project_top)/m4/
Next, you write like below in configure.ac:
AX_CXX_COMPILE_STDCXX_11([noext], [mandatory])
And exec, you can check it's possible or not to use C++11 feature in the platform
$ autoreconf -vi -I m4
$ ./configure
and
-I/path/to/include/libfoo (or libbar, or Eigen3)
-L/path/to/lib/ (Where libfoo and libbar reside)
-lfoo
This is difficult to explain simply,
The library provides .pc file
You should use PKG_CHECK_MODULES macro
You should refer Guide to pkg-config and The PKG_CHECK_MODULES Macro
This would help to receive include path and library path.
The library provides foo-config shell
For example, libcurl provides curl-config, libxml2 provides xml2-config. So, we can get include/lib path using this shell.
CURL_LIBS=`$CURLCONFIG --libs`
CURL_CFLAGS=`$CURLCONFIG --cflags`
The library written in C and provides nothing
You should use AC_CHECK_HEADER/AC_CHECK_LIB
You can refer about it AC_CHECK_HEADER , AC_CHECK_LIB
The library written in C++ and provides nothing
Use AC_TRY_LINK/AC_LANG_PUSH, AC_LANG_POP like below...
AC_MSG_CHECKING([for some_cpp_lib])
AC_LANG_PUSH(C++)
SAVE_LIBS="$LIBS"
LIBS="$LIBS -lsome_cpp_lib"
AC_TRY_LINK([#include <some_cpp_lib.hpp>],
[SomeCppLib object;],
has_some_cpp_lib=1,
has_some_cpp_lib=0)
AC_LANG_POP(C++)
if test $has_some_cpp_lib = 0; then
AC_MSG_RESULT([no])
else
AC_MSG_RESULT([yes])
fi
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