当我构建一个使用FFF(Fake Function Framework)的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'
该项目有一个源文件:
模块测试应用程序:
#include <gtest/gtest.h>
extern "C" {
#include "fff.h"
FAKE_VALUE_FUNC(uint16_t, MODULEA_getSampleValue);
}
extern "C" {
#include "module_b.h"
}
// Tests written here
那么“module_b.h”本身#包括“module_a.h”。我不明白是什么导致了未定义的引用错误。我正在使用Cmake构建项目,我可能也配置不正确。测试的CMakeLists.txt是:
CMakeLists.txt:
add_executable(module_test
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)
我在这里错误地配置了什么,会导致这个未定义的引用错误?