Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Boost and Autoconf

I am making a project that uses Autoconf. I have the following in configure.ac:

AC_CHECK_HEADERS([boost/foreach.hpp], [],
    [AC_MSG_ERROR(You need the Boost libraries.)])

When I run configure, it says it cannot find this header file:

checking boost/foreach.hpp usability... no
checking boost/foreach.hpp presence... no
checking for boost/foreach.hpp... no
configure: error: You need the Boost libraries.

This is strange, because I have Boost. If I remove the check, the code compiles, and I have Boost installed:

$ find /usr/include -name foreach.hpp
/usr/include/boost/foreach.hpp
/usr/include/boost/test/utils/foreach.hpp

Note that I did exactly the same with SDL, and it works.

AC_CHECK_HEADERS([SDL/SDL.h], [],
    [AC_MSG_ERROR(You need the SDL development library.)])

...

checking SDL/SDL.h usability... yes
checking SDL/SDL.h presence... yes
checking for SDL/SDL.h... yes
like image 450
petersohn Avatar asked Jun 21 '10 19:06

petersohn


People also ask

How does Autoconf work?

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.

Does Boost work with C?

Boost can't be used with C as it uses OOP features from C++.


2 Answers

AC_CHECK_HEADERS actually does a a compile check, not an existence check. So you have to set C++ support for compilation tests in order for boost headers to compile (default is C, docs here):

AC_LANG_PUSH([C++])
AC_CHECK_HEADERS([boost/foreach.hpp], [],
    [AC_MSG_ERROR(You need the Boost libraries.)])
AC_LANG_POP([C++])
like image 89
academicRobot Avatar answered Oct 11 '22 14:10

academicRobot


There's also a collection of Boost autoconf macros at the GNU Autoconf Archive. You'll probably need at least AX_BOOST_BASE. Other macros for the other Boost libs are there also.

like image 34
ldav1s Avatar answered Oct 11 '22 12:10

ldav1s