链接器处对“fff”的未定义引用

问题描述 投票:0回答:1

当我构建使用 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'

该项目有源文件:

module_tests.cpp:



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 是:

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)

我在这里配置不正确会导致此未定义的引用错误?

c++ c cmake googletest fake-function-framework
1个回答
1
投票

您需要定义FFF所需的全局变量。如果你查看 github 页面,或者 FFF 中包含的任何测试,你会发现有一行

DEFINE_FFF_GLOBALS;

扩展到所需的

fff
的定义。

fff_globals_t fff;
© www.soinside.com 2019 - 2024. All rights reserved.