简体   繁体   English

GNU Autotools-如何处理必需但可能缺少的标题?

[英]GNU Autotools - How to handle required but possibly missing headers?

I was wondering about the best-practice solution of handling required headers with GNU Autotools. 我想知道使用GNU Autotools处理所需标头的最佳实践解决方案。 This is one line from my configure.ac 这是我的configure.ac一行

AC_CHECK_HEADERS_ONCE(argp.h)

If the argp.h is missing on a system, then configure will just proclaim 如果系统上缺少argp.h ,则configure会声明

...
checking for argp.h... no
...

but do nothing about it. 但是什么也不要做。 Of course, the program will fail to compile, because the expected header does not exist, and wrapping the include in #ifdef HAVE_ARGP_H directives, and possibly adding an #else #error [...] construct would do what I want, but it seems rather tedious. 当然,该程序将无法编译,因为预期的标头不存在,并且将包含的内容包装在#ifdef HAVE_ARGP_H指令中,并且可能添加#else #error [...]结构#ifdef HAVE_ARGP_H我的要求,但是似乎很乏味。

Is there a good way to error out on missing but required headers on configure time as opposed to compile time? 有没有一种好的方法来在配置时(而不是编译时)出错但缺少所需的标头?

Thanks, Andy 谢谢,安迪

Replace your AC_CHECK_HEADERS_ONCE call with: 将您的AC_CHECK_HEADERS_ONCE呼叫替换为:

AC_CHECK_HEADER([argp.h], [], AC_MSG_ERROR([cannot find required header argp.h]))

This variant won't define HAVE_ARGP_H , but you don't need that anyway since your code requires that header unconditionally. 这个变体不会定义HAVE_ARGP_H ,但是您仍然不需要它,因为您的代码无条件地需要该标头。 The error stops the configure process. 该错误将停止配置过程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM