如果用c++重写C项目的部分代码,但遗漏了相同的API,是否存在ABI兼容性问题?

Is there an ABI compatibility issue if part of the code of a C project is rewritten in C++, but with the same API left out?

本文关键字:API 是否 兼容性 ABI 存在 问题 重写 c++ 项目 如果 代码      更新时间:2023-10-16

对于用C编写的共享库项目,如果我用c++重写部分代码,但保留完全相同的api,我会有任何ABI兼容性问题吗?

如果你保持相同的API(函数名和参数类型),你应该很好。

需要做的是用这个(copy &(从这里粘贴):

#ifdef __cplusplus
extern "C" {
#endif
// all of your legacy C code here
#ifdef __cplusplus
}
#endif

这可以确保c++编译器不会混淆这些名称,因此C编译器的外部符号仍然可以与导出链接。