在googletest测试c/c++函数过程中碰到这个问题,记录一下出现这个问题可能的原因:
1.add()这个函数的源文件(add.c)路径没有添加到CMakeLists.txt文件中。
2.如果你又测试了另一个函数writetofile(),但是这个函数是定义在.cpp文件中的,那么测试程序中添加头文件时不能添加在
extern "C"{
#include "add.h"
#include "writetofile.h"
}
内,这样写也会报 undefined reference to ‘add’ 这个错误。应该写为:
extern "C"{
#include "add.h"
}
#include "writetofile.h"