我在构建使用 autoconf 的 C 项目时经常遇到这个问题,所以我正在寻找一种可重复的方法来做到这一点。我经常有一个库,我想在其中 undef
一个由 autoheader 在 config.h
文件中生成的宏。例如 - 现在我想确保 #define CLOCK_GETTIME 1
生成为 #undef CLOCK_GETTIME
。
假设在此示例中,像这样检查clock_gettime
。
AC_CHECK_FUNCS([clock_gettime])
过去,我手动编辑文件以删除定义。但我不敢相信没有什么东西我不能直接传递给 ./configure
来覆盖 AC_CHECK_FUNCS
的默认行为。
如何更改 autoconf 决定在我的 config.h
中定义的内容?
最佳答案
./configure 'ac_cv_func_clock_gettime=no'
应该管用。例如:
mkdir foo
cd foo
printf '%s\n' \
'AC_INIT([foo], [0.1])' \
'AC_CONFIG_HEADERS([config.h])' \
'AC_CHECK_FUNCS([clock_gettime])' \
'AC_OUTPUT' \
> configure.ac
autoheader
autoconf
./configure >/dev/null 2>&1 \
&& grep CLOCK_GETTIME config.h
./configure 'ac_cv_func_clock_gettime=no' >/dev/null 2>&1 \
&& grep CLOCK_GETTIME config.h
我的系统上的输出:
#define HAVE_CLOCK_GETTIME 1
/* #undef HAVE_CLOCK_GETTIME */
AC_CHECK_FUNC
创建的所有缓存变量, AC_CHECK_FUNCS
,和AC_CHECK_FUNCS_ONCE
具有 the official documentation 中描述的一般形式:
This macro caches its result in the
ac_cv_func_<em>function</em>
variable.
以下是更多示例:
ac_cv_func_strcasecmp # AC_CHECK_FUNC([strcasecmp])
ac_cv_func_mempcpy # AC_CHECK_FUNC([mempcpy])
ac_cv_func_pthread_create # AC_CHECK_FUNC([pthread_create])
关于c - 如何强制autoconf不定义宏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66378130/