C 中的条件编译,当函数使用 automake 具有不同的原型(prototype)时

标签 c automake

ibv_modify_qp 函数针对不同版本的库有 2 个不同的签名。 这两个库都将头文件安装在同一位置。以下是 2 个版本。

int ibv_modify_qp(struct ibv_qp *qp, struct ibv_qp_attr *attr,
              int attr_mask);
int ibv_modify_qp(struct ibv_qp *qp, struct ibv_qp_attr *attr,
              enum ibv_qp_attr_mask attr_mask);

在我的库中,我将驱动程序特定函数的指针传递给 ibv_context_ops 结构。

/*ibv_context_ops field contains function pointers to driver specific functions*/

static struct ibv_context_ops c4iw_ctx_ops = {
    .modify_qp = c4iw_modify_qp,
    }
int c4iw_modify_qp(struct ibv_qp *ibqp, struct ibv_qp_attr *attr,
               int attr_mask);

所以当原型(prototype)匹配时我没有看到任何警告,但是当原型(prototype)不同时,就会产生警告。 现在我正在使用 CFLAGS 进行条件编译,如下所示。

#ifdef IBV_VER2

int c4iw_modify_qp(struct ibv_qp *ibqp, struct ibv_qp_attr *attr,
               int attr_mask);

#else

int c4iw_modify_qp(struct ibv_qp *ibqp, struct ibv_qp_attr *attr,
               enum ibv_qp_attr_mask attr_mask);
#endif

我是否可以利用 gnu automake 检查函数原型(prototype)并根据库头文件中定义的函数原型(prototype)替换函数参数。

最佳答案

函数原型(prototype)几乎相同。传递给函数的整数和枚举值之间没有真正的区别。所以在你的情况下你根本不需要做任何编译器魔术。如果您提供编译器警告的更多详细信息,我会修改答案。

Is there anyway I can make use of gnu automake to check for function prototype and substitute function arguments based on the function prototype defined in the library header file.

如果您确实有不同的 API,您可以简单地创建一个只用其中一个版本编译的最小程序。程序是否编译通过,可以作为条件编译的依据。

参见:http://www.gnu.org/software/autoconf/manual/autoconf.html#Running-the-Compiler

示例:https://svn.apache.org/repos/asf/xerces/c/trunk/configure.ac

关于C 中的条件编译,当函数使用 automake 具有不同的原型(prototype)时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19465228/

相关文章:

c++ - 使用 libtool 和 autoconf 构建 ASM 代码

c - 将字符串指针传递给 lua

c - 交换字符串数组中的元素

autotools - 'make distcheck' 目标和 info/dir 文件

c - autoreconf 失败并显示 "possibly undefined macro: AM_PATH_GLIB_2_0"

linker - 如何将共享库与 --as-needed 与 automake 链接?

c - 将 URL 传递给从 WAV 文件中提取样本的特定示例代码

C循环跳过输入迭代

c - 在c中输入单个字符

testing - 在 hudson 中设置测试构建作业,检测 make 何时无法编译