C++:与C混合编程 CMake undefined reference to
问题描述
.cpp 和 .c 混合编程时,CMake 中添加了依赖的.c文件,头文件目录也添加了,但是会报error undefined reference to 函数。
需要在头文件中添加下面的代码,cmake 就可以编译pass,生成正确的exe。
#ifdef __cplusplus
extern "C"
{
#endif
//代码部分
#ifdef __cplusplus
}
#endif
.cpp 和 .c 混合编程时,CMake 中添加了依赖的.c文件,头文件目录也添加了,但是会报error undefined reference to 函数。
需要在头文件中添加下面的代码,cmake 就可以编译pass,生成正确的exe。
#ifdef __cplusplus
extern "C"
{
#endif
//代码部分
#ifdef __cplusplus
}
#endif