关于Cmake 链接静态库出现undefined reference to错误

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/linux_Allen/article/details/80218406

在编写一个C++项目的时候,使用cmake管理工程,成功链接一个静态库,但是在编译时仍然出现undefined reference to 的错误。
最终发现问题是由于c和c++混编导致的。

解决方案:
由于我链接的库是使用c语言编写,所以需要在include头文件时加上

#ifdef __cplusplus
extern "C"
{
#endif
#include "XXX.h"
#ifdef __cplusplus
}
#endif

猜你喜欢

转载自blog.csdn.net/linux_Allen/article/details/80218406