gpt4 book ai didi

c++ - LNK2019 与 Qt 和 Gmock

转载 作者:太空宇宙 更新时间:2023-11-04 12:50:42 24 4
gpt4 key购买 nike

<分区>

在过去的几天里,我一直在用头撞墙。我正在尝试将 googletest 的 gmock 库合并到我的 Qt Autotest 子目录项目中,但一直收到以下链接器错误,我不确定如何解决此问题。主应用程序编译并运行得很好。

tst_reptileprofile.obj : error LNK2019: unresolved external symbol "public: __thiscall DashboardWidget::DashboardWidget(void)" (??0DashboardWidget@@QAE@XZ) referenced in function "private: void __thiscall TestReptileProfile::init(void)" (?init@TestReptileProfile@@AAEXXZ)

测试代码如下:

#include <QtTest/QtTest>
#include <QCoreApplication>
#include <QObject>
#include "gmock/gmock.h"

#include "../Application/dashboardwidget.h"

class TestReptileProfile : public QObject
{
Q_OBJECT

public:
TestReptileProfile() {}
~TestReptileProfile() {}

private slots:
void initTestCase()
{
}
void cleanupTestCase()
{
}

void init()
{
dashboard_ = new DashboardWidget();
}

void cleanup()
{
delete dashboard_;
}

private:
DashboardWidget* dashboard_;

};

#include "tst_reptileprofile.moc"
QTEST_MAIN(TestReptileProfile)

DashboardWidget.h/.cpp

#pragma once

#include <QtWidgets/QWidget>
#include <QtWidgets/QAbstractButton>

namespace Ui {
class DashboardWidget;
}

class DashboardWidget : public QWidget
{
Q_OBJECT

public:
explicit DashboardWidget();
~DashboardWidget();
QAbstractButton* openProfileButton();

private:
Ui::DashboardWidget *ui;
QAbstractButton* openProfileButton_;
};

#include "dashboardwidget.h"
#include "ui_dashboardwidget.h"

DashboardWidget::DashboardWidget() :
ui(new Ui::DashboardWidget)
{
ui->setupUi(this);
openProfileButton_ = ui->openReptileProfilePageButton;
}

DashboardWidget::~DashboardWidget()
{
delete ui;
}

QAbstractButton* DashboardWidget::openProfileButton()
{
return openProfileButton_;
}

子目录项目.pro

TEMPLATE = subdirs

CONFIG += ordered

SUBDIRS += \
Application \
AutoTests

AutoTests.depends = Application

Application.pro

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = Application
TEMPLATE = app

DEFINES += QT_DEPRECATED_WARNINGS

SOURCES += \
main.cpp \
mainview.cpp \
. . .
mainpresenter.cpp \
dashboardwidget.cpp \


FORMS += \
mainview.ui \
i_mainpresenter.h \
dashboardwidget.ui \

HEADERS += \
mainview.h \
dashboardwidget.h \

AutoTests.pro

QT += testlib
QT += gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

CONFIG += qt warn_on depend_includepath testcase

TEMPLATE = app

SOURCES += \
tst_reptileprofile.cpp

unix|win32: LIBS += -L$$PWD/../../../googletest/googlemock/msvc/2015/Win32-Release/ -lgmock

INCLUDEPATH += $$PWD/../../../googletest/googlemock/msvc/2015/Win32-Release
DEPENDPATH += $$PWD/../../../googletest/googlemock/msvc/2015/Win32-Release

INCLUDEPATH += D:\googletest\googlemock\include\
INCLUDEPATH += D:\googletest\googletest\include\

我还尝试将项目转换为导致编译错误的 Visual Studio 项目。

Error   C2059   syntax error: '.'   AutoTests   ProjectDir\tst_reptileprofile.cpp   63  

谢谢

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com