当 .h 文件明确可用时,为什么 autoconf 不能通过 AC_CHECK_HEADER 测试? [英] Why doesn't autoconf pass the AC_CHECK_HEADER test when the .h is file clearly available?

查看:29
本文介绍了当 .h 文件明确可用时,为什么 autoconf 不能通过 AC_CHECK_HEADER 测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我花了一些时间让 autoconf 检查特定头文件的存在.

I am having a bear of a time getting autoconf to check for the presence of a particular header file.

让我们将头文件依赖项称为inky.h",假设 inky 是一个(单独)安装的库,前缀设置为/usr/local".这将inky.h"放在/usr/local/inky/inky.h 中,将 libinky.so 放在/usr/local/lib 中.

Let's call the header dependency "inky.h", and let's say that inky is a library that was installed (seperately) with the prefix set to "/usr/local". This put "inky.h" in /usr/local/inky/inky.h and libinky.so in /usr/local/lib.

现在,我正在尝试验证 inky.h 在我的应用程序 configure.ac 中的存在,如下所示:

Now, I'm trying to verify the presence of inky.h in my applications configure.ac as follows:

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 之后):

This produces the following output from ./configure (after an 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 的第四个参数中,如下所示:

Now, this appears to be the case because inky.h includes 2 other headers, so I add them in on the fourth parameter of AC_CHECK_HEADER like so:

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 渲染此输出:

Which renders this output from ./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 宏失败?

I'm at my wits end with autoconf. Does anyone have any idea where I'm going wrong here. Is it possible to get configure to provide more details about what is failing? Why can I find the file itself, but the AC_CHECK_HEADER macro fails?

另外,请不要告诉我使用不同的软件包分发套件.我自己永远不会选择 Autoconf,但我确实必须向预先存在的项目添加一些依赖项.

Also, please don' tell me to use a different package distribution suite. I would never have chosen Autoconf myself, but I do have to add some dependencies to a pre-existing project.

另请注意,实际库未命名为inky".但是,这个项目存在仅供官方使用"的问题,所以我改了名字来保护......好吧,保护自己!

Also note that the actual library is not named "inky." However, there is an issue of "official use only" for this project, so I have changed the names to protect the...well, to protect myself!

想通了问题所在.看我的回答.

Figured out the problem. See my answer.

推荐答案

我找到了问题所在.我正在使用的库是一个 C 库,但我链接的inky"库是一个 C++ 库.因此,在 configure.ac 脚本的早期,语言 (AC_LANG) 被设置为 C.在执行inky"检查时,我需要将语言更改为 C++,以便 Autoconf 使用 C++ 编译器而不是 C 编译器.这很容易通过使用:

I found what the issue was. The library that I am working with is a C library, but the "inky" library that I am linking against is a C++ library. So, the language (AC_LANG) was set to C early in the configure.ac script. While performing checks for "inky", I needed to change the language to C++ so that Autoconf used the C++ compiler instead of the C compiler. This was done rather easily by using:

AC_LANG_PUSH([C++])
dnl # Do the checks for inky
AC_LANG_POP([C++])

这既解决了我在此线程中询问的问题,也解决了我手头尚未发布的问题,其中我无法使 AC_CHECK_LIB 宏正常工作.

This solved both the problem that I asked about in this thread, and on that I hand't posted yet wherein I couldn't get the AC_CHECK_LIB macro to work.

感谢大家的投入.

这篇关于当 .h 文件明确可用时,为什么 autoconf 不能通过 AC_CHECK_HEADER 测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆