For the ProbABEL project I’m working on I wanted to test for the presence of the Eigen header files using . Eigen is a C++ template library for linear algebra. It basically consists of a bunch of header files. On my PC the Eigen files are installed in /usr/include/eigen3/ since I used the Debian/Ubuntu libeigen3-dev package.

I first tried to test for the headers by simply including

AC_CHECK_HEADERS([eigen3/Eigen/Dense])

in configure.ac, but that didn’t work:

...
checking eigen3/Eigen/Dense usability... no
checking eigen3/Eigen/Dense presence... no
checking for eigen3/Eigen/Dense... no
...

It turns out that you have to add the following lines to configure.ac:

AC_LANG_PUSH([C++])
AC_CHECK_HEADERS([eigen3/Eigen/Dense])
AC_LANG_POP([C++])

Now I get the following output when running ./configure:

...
checking how to run the C++ preprocessor... g++ -E
checking eigen3/Eigen/Dense usability... yes
checking eigen3/Eigen/Dense presence... yes
checking for eigen3/Eigen/Dense... yes
...

To go into a bit more detail, these are the errors in config.log without the AC_LANG options:

...
configure:4877: checking eigen3/Eigen/Dense usability
configure:4877: gcc -c -g -O2 -Wall conftest.c >&5
In file included from /usr/include/eigen3/Eigen/Core:35:0,
                 from /usr/include/eigen3/Eigen/Dense:1,
                 from conftest.c:67:
/usr/include/eigen3/Eigen/src/Core/util/Macros.h:188:5: error: unknown type name 'namespace'
/usr/include/eigen3/Eigen/src/Core/util/Macros.h:188:21: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token
In file included from /usr/include/eigen3/Eigen/Dense:1:0,
                 from conftest.c:67:
/usr/include/eigen3/Eigen/Core:98:12: error: expected identifier or '(' before string constant
In file included from /usr/include/eigen3/Eigen/Dense:1:0,
                 from conftest.c:67:
/usr/include/eigen3/Eigen/Core:144:18: fatal error: cerrno: No such file or directory
...

It seems to be the case that AC_LANG is set to C instead of C++ and consequently compilation of autoconf’s test programme fails. The AC_LANG_PUSH option forces autoconf to use C++.

Thanks to this post on Stack Overflow I could solve this problem.

Related Images: