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/