8wDlpd.png
8wDFp9.png
8wDEOx.png
8wDMfH.png
8wDKte.png

QTest 单元测试:未定义符号

lukep 1月前

17 0

我正在尝试为我的应用程序编写单元测试。第一次尝试时,由于未定义的符号,我的单元测试构建无法链接。ld.lld: 错误:未定义符号:AnalysisEngine::

我正在尝试为我的应用程序编写单元测试。第一次尝试时,由于未定义的符号,我的单元测试构建无法链接。

ld.lld: error: undefined symbol: AnalysisEngine::diagnosisDetected(Diagnosis)
>>> referenced by ../code/core/src/analysisengine.cpp:18
>>>               ../code/core/src/analysisengine.cpp.obj:(AnalysisEngine::parseBuffer())
>>> referenced by ../code/core/src/analysisengine.cpp:22
>>>               ../code/core/src/analysisengine.cpp.obj:(AnalysisEngine::parseBuffer())
>>> referenced by ../code/core/src/analysisengine.cpp:26
>>>               ../code/core/src/analysisengine.cpp.obj:(AnalysisEngine::parseBuffer())

ld.lld: error: undefined symbol: AnalysisEngine::staticMetaObject
>>> referenced by ../code/core/src/analysisengine.cpp.obj:(.refptr._ZN14AnalysisEngine16staticMetaObjectE)

ld.lld: error: undefined symbol: vtable for AnalysisEngine
>>> referenced by ../code/core/src/analysisengine.cpp.obj:(.refptr._ZTV14AnalysisEngine)

我的单元测试依赖于 AnalysisEngine() 类并对其进行了实例化。在我的普通应用程序中,它可以很好地链接和构建,但由于某种原因,信号出现了问题 diagnosisDetected 。链接器为什么找不到它?(所有相关代码如下)

.h

#ifndef ANALYSISENGINE_H
#define ANALYSISENGINE_H

#include <QObject>
#include <QTimer>
#include "framebuffer.h"
#include "diagnosis.h"

class AnalysisEngine : public QObject {
    Q_OBJECT

public:
    explicit AnalysisEngine(QObject *parent = nullptr);
    bool flatliningCheck();
    bool tachycardiaCheck();
    bool arrhythmiaCheck();

signals:
    void diagnosisDetected(Diagnosis diagnosis);

private:
    QTimer analysisTimer;
    FrameBuffer* buffer;
    void parseBuffer();
};

#endif // ANALYSISENGINE_H

.cpp的相关部分


#include "analysisengine.h"
#include <QDebug>
#include <cmath>

AnalysisEngine::AnalysisEngine(QObject *parent)
    : QObject(parent)
{
    connect(&analysisTimer, &QTimer::timeout, this, &AnalysisEngine::parseBuffer);
    analysisTimer.start(3000);  // Run analysis every two seconds
}

void AnalysisEngine::parseBuffer() {
    QMutexLocker locker(buffer->lock());

    if (flatliningCheck()) {
        qDebug() << "Diagnosis Detected: FLATLINE";
        emit diagnosisDetected(Diagnosis::FLATLINING);
    }
    if (tachycardiaCheck()) {
        qDebug() << "Diagnosis Detected: TACHYCARDIA";
        emit diagnosisDetected(Diagnosis::TACHYCARDIA);
    }
    if (arrhythmiaCheck()) {
        qDebug() << "Diagnosis Detected: ARRHYTHMIA";
        emit diagnosisDetected(Diagnosis::ARRHYTHMIA);
    }
}

diagnostic.h 包含信号中使用的枚举,并包含在 analysisengine.h 中

#ifndef DIAGNOSIS_H
#define DIAGNOSIS_H

enum class Diagnosis {
    FLATLINING,
    TACHYCARDIA,
    ARRHYTHMIA
};

#endif // DIAGNOSIS_H

我的单元测试(Qtest)cmakelists.txt:

cmake_minimum_required(VERSION 3.5)

project(CoreUnitTests LANGUAGES CXX)

enable_testing()

find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Gui Test)
find_package(Qt6 REQUIRED COMPONENTS Gui Test)

set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

add_executable(CoreUnitTests tst_TestAnalysisEngine.cpp
                             test_analysisengine.h
                             ../../code/core/src/analysisengine.cpp
                             ../../code/core/src/framebuffer.cpp
                             ../../code/core/inc/diagnosis.h)

add_test(NAME TestAnalysisEngine COMMAND TestAnalysisEngine)

target_include_directories(CoreUnitTests PRIVATE
    ../../code/core/inc  # Add the core headers to the include path
    ./
)

target_link_libraries(CoreUnitTests PRIVATE Qt6::Gui Qt6::Test)
帖子版权声明 1、本帖标题:QTest 单元测试:未定义符号
    本站网址:http://xjnalaquan.com/
2、本网站的资源部分来源于网络,如有侵权,请联系站长进行删除处理。
3、会员发帖仅代表会员个人观点,并不代表本站赞同其观点和对其真实性负责。
4、本站一律禁止以任何方式发布或转载任何违法的相关信息,访客发现请向站长举报
5、站长邮箱:yeweds@126.com 除非注明,本帖由lukep在本站《qt》版块原创发布, 转载请注明出处!
最新回复 (0)
  • 为什么我需要一个用于生产代码的库?在我见过的(几乎)所有例子中,这都不是必需的(例如

  • 目前,上面显示的 CMakeLists.txt 位于包含我的主要项目 CMakeLists.txt 的目录中,但它未被标识为子目录。它是它自己的顶级文件。那应该有所不同吗?只要我有适当的包含,它不应该能够作为独立文件工作吗?

返回
作者最近主题: