简体   繁体   English

autoconf:如何检查#define的存在

[英]autoconf: how to check for presence of #define

I am writing a program that uses boost::asio to access serial ports. 我正在编写一个使用boost::asio访问串行端口的程序。 According to the documentation, serial port support is available when the BOOST_ASIO_HAS_SERIAL_PORT macro is defined. 根据文档,定义BOOST_ASIO_HAS_SERIAL_PORT宏后即可使用串行端口支持。 Since this is a requirement, I want my configure script to abort if the macro has not been defined. 由于这是一项要求,因此如果未定义宏,我希望我的配置脚本中止。

I thought I could achieve this with something like the following: 我以为可以通过以下方式实现此目的:

AC_MSG_CHECKING([for serial port support in boost::asio])
AC_EGREP_CPP(yes_have_boost_asio_serial, [
#include <boost/asio.hpp>
#ifdef BOOST_ASIO_HAS_SERIAL_PORT
yes_have_boost_asio_serial
#endif
], [
    AC_MSG_RESULT([yes])
], [
    AC_MSG_RESULT([no])
    AC_ERROR([boost::asio must be compiled with serial port support enabled])
])

Unfortunately when I put this in, I get a weird error when generating the configure script: 不幸的是,当我把它放进去时,生成配置脚本时出现一个奇怪的错误:

configure.ac:23: error: possibly undefined macro: BOOST_ASIO_HAS_SERIAL_PORT
      If this token and others are legitimate, please use m4_pattern_allow.
      See the Autoconf documentation.

Why is autoconf seeing macros inside my code? 为什么autoconf在我的代码中看到宏? The documentation on m4_pattern_allow more or less says if you have to use it something has gone wrong, so what have I done wrong? m4_pattern_allow上的文档或多或少说明如果必须使用它,出现了问题,那么我做错了什么?

I ended up just using m4_pattern_allow , I guess it has something to do with an all-uppercase symbol looking like something autoconf should deal with? 我最终只使用了m4_pattern_allow ,我想它与全大写符号有关,就像autoconf应该处理的一样?

m4_pattern_allow([BOOST_ASIO_HAS_SERIAL_PORT])

AC_MSG_CHECKING([for serial port support in boost::asio])
...

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

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