c和c++对函数的处理方式是不同的。
#ifdef __cplusplus
extern "C" {
#endif
...... // 代码段
#ifdef __cplusplus
}
#endif
C++调用c的函数时,在c++的 .h文件中加入 extern "C" { }, 是告诉C++编译器括号里的代码函数是按照C的文件格式编译的,要连接的话按照C的命令规则去找。
比如:
bool forMaxValue(int a, int b) // c语言中生成的符号大致为 _forMaxValue
{
return a > b;
}
bool forMaxValue(char a, char b) // c++ 中生成的符号大致为 _forMaxValue_char_char
{
return a > b;
}
参考: