让autoconf检查是否存在特定的头文件是一件很麻烦的事情。
让我们将头依赖项称为"inky.h",并假设inky是一个(单独)安装的库,其前缀设置为"/usr/local“。这会将"inky.h“放在/usr/local/inky/inky.h中,将libinky.so放在/usr/local/lib中。
现在,我正在尝试验证我的应用程序configure.ac中是否存在inky.h,如下所示:
dnl # Setup temp LDFLAGS and look for inky library/header
LDFLAGS_SAVE=${LDFLAGS};
CPPFLAGS_SAVE=${CPPFLAGS};
dnl # Look for inky on the user specified inky install path
LDFLAGS ="-L${inky_library_path}";
CPPFLAGS="-I${inky_include_path}/inky";
AC_MSG_NOTICE([Looking for inky.h using: ${CPPFLAGS}]);
dnl # This check finds inky.h just fine. This check was only used for debugging
AC_CHECK_FILE(
[${inky_include_path}/inky/inky.h],
[AC_MSG_NOTICE([Found inky.h])],
[AC_MSG_NOTICE([Didn't find inky.h])]
)
dnl # Look for the inky header file. If it isn't found, terminate.
AC_CHECK_HEADER(inky.h,
[],
[AC_MSG_ERROR([Couldn't find or include inky.h])]
)这将从./configure生成以下输出(在autoreconf -vfi之后):
configure: Looking for inky.y in fetk include path: -I/usr/local/include/inky.y
checking for /usr/local/include/inky/inky.h... yes
configure: Found inky.h
checking inky.h usability... no
checking inky.h presence... yes
configure: WARNING: inky.h: present but cannot be compiled
configure: WARNING: inky.h: check for missing prerequisite headers?
configure: WARNING: inky.h: see the Autoconf documentation
configure: WARNING: inky.h: section "Present But Cannot Be Compiled"
configure: WARNING: inky.h: proceeding with the compiler's result
checking for inky.h... no
configure: error: Couldn't find or include inky.h现在,情况似乎就是这样,因为inky.h包含了另外两个头文件,所以我将它们添加到AC_CHECK_HEADER的第四个参数中,如下所示:
dnl # Look for the inky header file. If it isn't found, terminate.
AC_CHECK_HEADER(inky.h,
[],
[AC_MSG_ERROR([Couldn't find or include inky.h])],
[dinky.h plinky.h]
)这将呈现来自./configure的输出:
configure: Looking for inky in fetk include path: -I/usr/local/include/inky
checking for /usr/local/include/inky/inky.h... yes
configure: Found inky.h
checking for inky.h... no
configure: error: Couldn't find or include inky.h我对autoconf束手无策。有没有人知道我哪里错了。是否可以进行配置以提供有关失败原因的更多详细信息?为什么我可以找到文件本身,但AC_CHECK_HEADER宏却失败了?
另外,请不要告诉我使用不同的包分发套件。我自己永远不会选择Autoconf,但我必须向一个预先存在的项目添加一些依赖项。
还要注意的是,实际的库并没有命名为“inky”。但是,这个项目存在“仅官方使用”的问题,所以我更改了名称来保护the...well,以保护我自己!
编辑-关闭解决了这个问题。请看我的回答。
发布于 2011-05-26 03:33:30
我找到问题所在了。我正在使用的库是一个C库,但是我正在链接的“墨水”库是一个C++库。因此,在configure.ac脚本的早期将语言(AC_LANG)设置为C。在执行"inky“检查时,我需要将语言更改为C++,以便Autoconf使用C++编译器而不是C编译器。这可以通过使用以下命令轻松完成:
AC_LANG_PUSH([C++])
dnl # Do the checks for inky
AC_LANG_POP([C++])这既解决了我在这个线程中询问的问题,也解决了我还没有发布的问题,在这个问题上,我无法使AC_CHECK_LIB宏工作。
感谢大家的投入。
发布于 2011-05-26 03:29:28
AC_CHECK_HEADER的第四个参数不是一个头部列表,而是一些执行包含的C代码。
也许可以尝试一些类似的东西
AC_CHECK_HEADER([inky.h],
[],
[AC_MSG_ERROR([Couldn't find or include inky.h])],
[#include <dinky.h>
#include <plinky.h>
])甚至是
AC_CHECK_HEADERS([dinky.h plinky.h inky.h],
[],
[AC_MSG_ERROR([Couldn't find or include this header])],
[#if HAVE_DINKY_H
# include <dinky.h>
#endif
#if HAVE_PLINKY_H
# include <plinky.h>
#endif
])发布于 2011-05-26 02:37:42
有关此测试失败原因的详细信息,请参阅config.log。不过,我的猜测是:
由于您没有将使用AC_CHECK_FILE找到的路径添加到CPPFLAGS或INCLUDES或autoconf正在使用的任何位置,因此days.
AC_CHECK_HEADER不会使用预处理器编译找到标头(原因不是CPPFLAGS includes中缺少标头)。https://stackoverflow.com/questions/6128987
复制相似问题