Pergunta

I would like to check the presence of the google sparsehash package in my C++ program with the Autotools.

Here is a minimal configure.ac:

AC_PREREQ([2.69])
AC_INIT([myprog], [1.0], [adress@email.com])
AC_CONFIG_SRCDIR([main.cpp])
AC_CONFIG_HEADERS([config.h])
AM_INIT_AUTOMAKE([foreign -Wall -Werror])

AC_PROG_CXX
AC_PROG_CC
AC_CHECK_HEADERS([google/sparse_hash_map])

AC_CONFIG_FILES(Makefile)
AC_OUTPUT

I run autoreconf -vfi, then ./configure, and I get:

checking google/sparse_hash_map usability... no
checking google/sparse_hash_map presence... no
checking for google/sparse_hash_map... no

However, I can check the presence of /usr/include/google/sparse_hash_map, a C++ file, which is a thin wrapper around /usr/include/google/sparsehash/sparsehashtable.h. Moreover, the tiny code:

#include <google/sparse_hash_map>
int main() {return 1;}

compiles and executes fine using g++ test.cpp.

Any suggestion for a newbie?

Foi útil?

Solução

The AC_CHECK_HEADER macro is using the C compiler by default. You can change the current language using: AC_LANG([C++]) or: AC_LANG_PUSH([C++]) / AC_LANG_POP - as described in the (single-page) manual. e.g.,

...
AC_LANG([C++])
AC_CHECK_HEADERS([google/sparse_hash_map])
# still in C++ 'mode'

or:

...
AC_LANG_PUSH([C++])
AC_CHECK_HEADERS([google/sparse_hash_map])
AC_LANG_POP([C++])
# restored previous language 'mode'
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top