c++ - autoconf: Set AC_CHECK_LIB compiler flags -


i trying set project use autotools build system distribution. however, having problem when comes including few libraries.

my code depends on few libraries:

  • one wrote (i'll call libfoo)

  • one third party (i'll call libbar)

  • eigen3 (which header files)

these compiled , installed in $home directory. not need build them part of project.

the flags need are

-std=c++11 (got taken care of) 

and

-i/path/to/include/libfoo (or libbar, or eigen3) 

and

-l/path/to/lib/ (where libfoo , libbar reside) 

and

-lfoo 

to compile , link against libfoo , libbar

the problem want set checks presence of libfoo , libbar , headers (i have check eigen3 set already). issue macros ac_check_headers , ac_check_lib don't seem want include required cppflags or ldflags, no matter how try define them, 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 configure trying compile against header using

g++ -std=c++11 (other flags...) 

but failing due missing flags above (the error "cannot find eigen3/dense", or similar, indicating missing -i flag)

i'm newbie autotools, may missing obvious, i've read through amount of , manuals , have far failed figure out need set up.

related: want user able manually specify location of libfoo , libbar via --with-libfoo-include (etc) if needed, need able specify configure detects these libraries. how can done?

all need are:

for

-std=c++11 (got taken care of)

is use ax_cxx_compile_stdcxx_11.m4
use it, need download above link , set in $(project_top)/m4/
next, write below in configure.ac:

ax_cxx_compile_stdcxx_11([noext], [mandatory]) 

and exec, can check it's possible or not use c++11 feature in platform

$ autoreconf -vi -i m4 $ ./configure 

and

-i/path/to/include/libfoo (or libbar, or eigen3)
-l/path/to/lib/ (where libfoo , libbar reside)
-lfoo

this difficult explain simply,

  1. the library provides .pc file
    should use pkg_check_modules macro
    should refer guide pkg-config , the pkg_check_modules macro
    receive include path , library path.

  2. the library provides foo-config shell
    example, libcurl provides curl-config, libxml2 provides xml2-config. so, can include/lib path using shell.

    curl_libs=`$curlconfig --libs`   curl_cflags=`$curlconfig --cflags`   
  3. the library written in c , provides nothing should use ac_check_header/ac_check_lib
    can refer ac_check_header , ac_check_lib

  4. the library written in c++ , provides nothing
    use ac_try_link/ac_lang_push, ac_lang_pop 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;   ac_msg_result([no]) else   ac_msg_result([yes]) fi 

Comments