当.h文件清晰可用时,为什么autoconf无法通过AC_CHECK_HEADER测试?

问题描述

| 我花了点时间让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还包含其他2个标头,因此我将它们添加到AC_CHECK_HEADER的第四个参数上,如下所示:
dnl # Look for the inky header file.  If it isn\'t found,[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”。但是,此项目存在一个“仅供官方使用”的问题,因此我更改了名称以保护...好,以保护自己! [编辑-结束] 找出问题所在。看我的答案。     

解决方法

我发现了问题所在。我正在使用的库是C库,但是要链接的\“ inky \”库是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
宏的问题。 谢谢大家的投入。     ,
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
])
    ,有关此测试失败的原因的详细信息,请参见ѭ10。我的猜测是: 由于您没有将
AC_CHECK_FILE
找到的路径添加到
CPPFLAGS
INCLUDES
或whatever14ѭ正在使用的这些路径中。
AC_CHECK_HEADER
未使用预处理程序编译找到标题(由于for12ѭ包含缺少标题的其他原因)。