我花了很长时间让 autoconf 检查特定头文件是否存在。
我们将标头依赖项称为“inky.h”,并假设 inky 是一个(单独)安装的库,前缀设置为“/usr/local”。这会将“inky.h”放入 /usr/local/inky/inky.h 中,将 libinky.so 放入 /usr/local/lib 中。
现在,我尝试验证 inky.h 在我的应用程序 configure.ac 中是否存在,如下所示:
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, 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”。然而,这个项目存在“仅限官方使用”的问题,所以我更改了名称以保护......好吧,为了保护我自己!
[编辑-结束]
找出问题所在了。看我的回答。