如何测试autoconf的AC_REPLACE_FUNCS?

时间:2016-06-08 16:50:38

标签: autotools autoconf automake

说我的configure.ac

AC_REPLACE_FUNCS(getopt_long)

我的src目录中有getopt_long.h和getopt_long.c。我如何强制将HAVE_GETOPT_LONG强制为0并将getopt_long.c与其他所有内容一起编译以进行测试?

1 个答案:

答案 0 :(得分:1)

我不确定这是最好的解决方法,因为您在可执行文件中包含getopt_long符号,该符号也链接到包含getopt_long符号的C标准库。可能无法正确解析这两个符号。但是,您可以尝试手动修改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定义,则不会发生符号冲突。

相关问题