当我构建使用 FFF(假函数框架)的 GoogleTest 可执行文件(使用 CMake)时,出现以下链接器错误:
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/module_test.dir/objects.a(module_tes
ts.cpp.obj):module_tests.cpp:(.rdata$.refptr.fff[.refptr.fff]+0x0): undefined reference to `fff'
该项目有源文件:
extern "C" {
#include "fff.h"
FAKE_VALUE_FUNC(uint16_t, MODULEA_getSampleValue);
}
extern "C" {
#include "module_b.h"
}
// Tests written here
然后“module_b.h”本身#include“module_a.h”。我不明白是什么导致了未定义的参考错误。我正在使用 Cmake 构建项目,我也可能配置不正确。用于测试的 CMakeLists.txt 是:
src/module_tests.cpp
)
target_link_libraries(module_test
PRIVATE
gtest_main
MODULE_A
MODULE_B
)
target_include_directories(module_test
PUBLIC
../inc
)
include(GoogleTest)
gtest_discover_tests(module_test)
我在这里配置不正确会导致此未定义的引用错误?
您需要定义FFF所需的全局变量。如果你查看 github 页面,或者 FFF 中包含的任何测试,你会发现有一行
DEFINE_FFF_GLOBALS;
扩展到所需的
fff
的定义。
fff_globals_t fff;