autoconf - autoconf中单方括号和双方括号的区别
问题描述
那么autoconf中的单方括号和双方括号有什么区别呢?
Autoconf 文档显示以下示例:
AC_CHECK_TYPES([float_t], [], [], [[#include <math.h>]])
恕我直言,它也适用于单括号:
AC_CHECK_TYPES([float_t], [], [], [#include <math.h>])
解决方案
如果你使用[[ ]]
你的宏参数,你可以在宏参数中随意使用[
和]
。另一方面,如果您使用[]
宏参数,[
并在宏参数中]
保留它们的特殊 autoconf/m4 含义。
如果宏参数中的实际文本包含括号,则差异变得明显,例如
dnl Minimum working example configure.ac. To run:
dnl touch Makefile.am && autoreconf -vis . && ./configure
AC_PREREQ([2.69])
AC_INIT([stackoverflow53609622], [0.0.1], [bugs@example.com])
AM_INIT_AUTOMAKE([-Wall -Werror foreign])
AC_PROG_CC
AC_MSG_CHECKING([compile example 1])
AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
const char hw[] = "Hello, World\n";
const char hs[] = "Hello, Stackoverflow\n";
]])], [AC_MSG_RESULT([yes])], [AC_MSG_RESULT([no])])
AC_MSG_CHECKING([compile example 2])
AC_COMPILE_IFELSE([AC_LANG_SOURCE([
const char hw[[]] = "Hello, World\n";
const char hs[[]] = "Hello, Stackoverflow\n";
])], [AC_MSG_RESULT([yes])], [AC_MSG_RESULT([no])])
AC_MSG_CHECKING([compile example 3])
AC_COMPILE_IFELSE([AC_LANG_SOURCE([
const char hw[] = "Hello, World\n";
const char hs[] = "Hello, Stackoverflow\n";
])], [AC_MSG_RESULT([yes])], [AC_MSG_RESULT([no])])
AC_CONFIG_FILES([Makefile])
AC_OUTPUT
示例 1 和 2 都将测试编译 C 程序
const char hw[] = "Hello, World\n";
const char hs[] = "Hello, Stackoverflow\n";
但是示例 3 将测试编译损坏的 C 程序
const char hw = "Hello, World\n";
const char hs = "Hello, Stackoverflow\n";
这将无法编译(请参阅config.log
编译器错误消息)。
但是,如果您将不平衡的括号放入宏参数文本中,m4
仍然会对宏参数的开始或结束位置感到非常困惑。AFAIK,解决这个问题的唯一方法是使用四边形(@<:@
for[
和@:>@
for ]
):
AC_MSG_CHECKING([compile example 4])
AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
const char hw[] = "Hello, World @<:@-:\n";
const char hs[] = "Hello, Stackoverflow\n";
]])], [AC_MSG_RESULT([yes])], [AC_MSG_RESULT([no])])
AC_MSG_CHECKING([compile example 5])
AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
const char hw[] = "Hello, World :-@:>@\n";
const char hs[] = "Hello, Stackoverflow\n";
]])], [AC_MSG_RESULT([yes])], [AC_MSG_RESULT([no])])
以下操作将在某个时间autoreconf
或configure
某个时间失败,这表明出现了非常错误的情况,您应该非常清楚地避免这种情况。
AC_MSG_CHECKING([compile example 6])
AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
const char hw[] = "Hello, World :-[\n";
const char hs[] = "Hello, Stackoverflow\n";
]])], [AC_MSG_RESULT([yes])], [AC_MSG_RESULT([no])])
AC_MSG_CHECKING([compile example 7])
AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
const char hw[] = "Hello, World :-]\n";
const char hs[] = "Hello, Stackoverflow\n";
]])], [AC_MSG_RESULT([yes])], [AC_MSG_RESULT([no])])
如需进一步阅读,您可以从https://www.gnu.org/savannah-checkouts/gnu/autoconf/manual/autoconf-2.69/html_node/M4-Quotation.html开始并从那里深入挖掘。
推荐阅读
- c# - .NET Core - 与另一个属性冲突的 JSON 属性名称
- sql-server - 与服务器建立连接成功,但在登录过程中出现错误,但问题出在Visual Studio
- java - 将 VB EBCDIC 文件转换为 ASCII,其中字帖记录以 01 分隔
- printing - 爱普生兼容热敏打印机的图像打印问题
- python - endoder4editing 神经网络中的“名称'net'未定义”(不是我的代码)
- javascript - 如何检查 JavaScript 中没有显示样式的第一个元素?
- python - 与原点距离的颜色点
- java - Android 主屏幕小部件 onclick 适用于模拟器,但并不总是适用于真实设备
- javascript - 比较 3 个数组并在 javascript 中找到组合
- html - 在eclipse中创建新的html文件时如何更改默认文本?