c++ - Qt 链接器错误窗口

标签 c++ qt linker

我正在尝试运行此代码,但我得到的只是链接器错误,并且真的不知道该怎么做或我在这里做错了什么。现在已经为此苦苦挣扎太久了,非常感谢任何帮助,这样我就可以让这件事继续下去。这也是我的第一个 Qt 应用程序。

运行 Qt Creator 3.5.1,基于 Qt 5.5.1(MSVC 2013,32 位) 编译器:微软Visual C++编译器12.0 操作系统:Windows 8.1 Pro 64位

我有 Qt 项目,其中有文件:

Hasher.h

#ifndef HASHER_H
#define HASHER_H

#include <QString>
#include <QCryptographicHash>

class Hasher : public QCryptographicHash
{
public:
    Hasher(const QByteArray &data, Algorithm method); /* Constructor */
    ~Hasher(); /* Destructor */

    QString name, output;
private:
    QCryptographicHash *QCryptObject;
};

#endif // HASHER_H

Hasher.cpp

#include "hasher.h"

/* Destructor */
Hasher::~Hasher() {

}

/*
 * Constructor Hasher(QByteArray &, Algorithm) generates hash
 * from given input with given algorithm-method
*/
Hasher::Hasher(const QByteArray &data, Algorithm method) {
   QByteArray result = this->QCryptObject->hash(data, method);
   this->output = result.toHex();
}

ma​​in.cpp

#include <QCoreApplication>
#include <QString>
#include <QFile>
#include <QDebug>

#include "hasher.h"

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    QString fileName;
    QTextStream stream(stdin);

    qDebug() << "MD5 generator!" << endl;
    qDebug() << "Give filename to generate checksum from: ";
    fileName = stream.readLine();
    QFile* file = new QFile(fileName);
        if(file->open(QIODevice::ReadOnly))
            {
                Hasher hasher(file->readAll(), QCryptographicHash::Md5);
                qDebug() << "MD5 Hash of " << fileName << " is: " << hasher.output << endl;
                file->close();
            }
    return a.exec();
}

我收到的错误:

main.obj:-1: error: LNK2019: unresolved external symbol "public: __cdecl Hasher::Hasher(class QByteArray const &,enum QCryptographicHash::Algorithm)" (??0Hasher@@QEAA@AEBVQByteArray@@W4Algorithm@QCryptographicHash@@@Z) referenced in function main

main.obj:-1: error: LNK2019: unresolved external symbol "public: __cdecl Hasher::~Hasher(void)" (??1Hasher@@QEAA@XZ) referenced in function main

debug\MD5-generator.exe:-1: error: LNK1120: 2 unresolved externals

.pro 文件

QT += core
QT -= gui

TARGET = MD5-generator
CONFIG += console
CONFIG -= app_bundle

TEMPLATE = app

SOURCES += main.cpp \
    hasher.cpp

HEADERS += \
    hasher.h

最佳答案

因此,链接器错误是由于未更新 makefile 和目标文件而导致的,因为新的 Hasher.cpp 根本没有完成。在这种情况下,重建项目可能会有所帮助:CleanRun qmakeBuild

关于c++ - Qt 链接器错误窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33442737/

相关文章:

c++ - "invalid_grant"- 通过 C++ 中的 Google 服务帐户与 googleapi 日历交互

qt - 我们可以让 QTableWidget 平滑滚动其内容吗?

ios - Xcode 找不到 XMPPFramework——如何修复链接器错误?

C++ 无法链接 Boost 库

c++ - C++中的cin忽略空格-基本编程

c++ - 在 QStringList 内部查找重复字符串并获取重复项的计数

c++ - 程序没有提供所需的输出

c++ - 通过 QML 仿函数对 C++ 模型进行排序和过滤?

c++ - 在 QWidget 中跟踪鼠标光标

c++ - 为什么我的 `.a` 文件中所有符号的值都是 0