Boost and Autoconf

13

我正在制作一个使用Autoconf的项目。我在configure.ac中有以下内容:

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

当我运行configure时,它说找不到这个头文件:
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.

这很奇怪,因为我已经安装了Boost。如果我去掉检查,代码就可以编译,而且我已经安装了Boost:

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

请注意,我对SDL做了完全相同的操作,它也可以正常工作。
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

检查config.log以查看它失败的原因。academicRobot可能是正确的,它正在尝试使用C编译器进行编译。 - William Pursell
3个回答

17

AC_CHECK_HEADERS实际上是进行编译检查而不是存在性检查。因此,为了使boost头文件能够编译(默认使用C),您需要设置C++支持进行编译测试(文档在此):

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

9

你可能会对github.com/tsuna/boost.m4感兴趣,它是一组Autoconf宏,可用于检查Boost头文件和库以及最低Boost版本。


9

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接