简体   繁体   English

AC_CHECK_HEADERS:在测试 header 存在之前定义一个宏

[英]AC_CHECK_HEADERS: define a macro before testing for header presence

A particular C++ logging library called spdlog that I use in my project has a broken package on CentOS (the platform I'm trying to compile on) where the header file will only compile if SPDLOG_FMT_EXTERNAL is defined before any of its files are included. A particular C++ logging library called spdlog that I use in my project has a broken package on CentOS (the platform I'm trying to compile on) where the header file will only compile if SPDLOG_FMT_EXTERNAL is defined before any of its files are included. [And this will not be fixed.] [这不会被修复。]

I am trying to find a way to use autoconf directives to test for the presence of this header file - previously I used a homegrown macro that compiles a program which uses that, but its speed latency is unacceptably slow so I am trying to replace it.我试图找到一种方法来使用 autoconf 指令来测试这个 header 文件的存在 - 以前我使用了一个自制的宏来编译一个使用它的程序,但它的速度延迟非常慢所以我试图替换它。

Here is the relevant snippet of my configure.ac :这是我的configure.ac的相关片段:

dnl check for libfmt is done earlier...
AC_CHECK_HEADERS([spdlog/spdlog.h], [have_spdlog="yes"], [have_spdlog="no"])
if test x$have_spdlog = xyes; then                                             
    LDFLAGS="$LDFLAGS -lspdlog -lfmt";                                  
else                                                              
    AC_MSG_ERROR([spdlog is required for logging support but is missing.])
fi

The header file spdlog/spdlog.h exists, but Autoconf deems it as not usable because it won't compile by itself. header 文件spdlog/spdlog.h存在,但 Autoconf 认为它不可用,因为它不会自行编译。

AC_CHECK_HEADERS has a parameter I can specify include files required to include that particular header file. AC_CHECK_HEADERS有一个参数,我可以指定包含该特定 header 文件所需的包含文件。 I can use that to specify the #define macro before the file is included.我可以在包含文件之前使用它来指定#define 宏。

Is there an easier way to just directly specify a macro without creating a new header file?有没有更简单的方法可以直接指定宏而不创建新的 header 文件?

After some experimenting, I learned that the fourth parameter to AC_CHECK_HEADERS accepts macros as well - anything that can be used in a C/C++ preprocessor works as well, such as #ifdef, #endif and so on.经过一些实验,我了解到AC_CHECK_HEADERS的第四个参数也接受宏 - 可以在 C/C++ 预处理器中使用的任何东西都可以,例如#ifdef、#endif 等。 It is not restricted to only #include directives.它不仅限于#include 指令。

AC_CHECK_HEADERS([spdlog/spdlog.h], [have_spdlog="yes"], [have_spdlog="no"], [
#define SPDLOG_FMT_EXTERNAL
])

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

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