我如何测试 autoconf 的 AC_REPLACE_FUNCS?

How do I test autoconf's AC_REPLACE_FUNCS?

说我有 configure.ac

AC_REPLACE_FUNCS(getopt_long)

我的 src 目录中有 getopt_long.h 和 getopt_long.c。我将如何强制 HAVE_GETOPT_LONG 以 0 结束,并且 getopt_long.c 与其他所有内容一起编译以用于测试目的?

我不确定这是最好的方法,因为您会在可执行文件中包含一个 getopt_long 符号,该符号也链接到 C 标准库,包括 getopt_long 象征。这两个符号可能无法正确解析。但是,您可以尝试手动编辑 config.h 并删除 #define HAVE_GETOPT_LONG.

更好的方法可能是编写如下代码:

#ifdef HAVE_GETOPT_LONG
inline
#endif
int
getopt_long_wrapper (int argc, char * const *argv, const char *shortopts,
                     const struct option *longopts, int *indexptr)
{
#ifdef HAVE_GETOPT_LONG
    return getopt_long (argc, argv, shortopts, longopts, indexptr);
#else
    /* your replacement function here */
#endif
}

那么如果去掉HAVE_GETOPT_LONG的定义,就不会有符号冲突了。