【发布时间】:2016-09-16 11:58:39
【问题描述】:
我有以下问题:
我想从主函数中的类创建对象。看起来这是一个链接器问题。您有什么想法,这个错误消息的原因可能是什么?
它的错误信息是:
main.obj:-1: error: LNK2019: Verweis auf nicht aufgelöstes externes Symbol ""public: __thiscall Test::Test(class QString)" (??0Test@@QAE@VQString@@@Z)" in函数“_main”。
main.obj:-1: error: LNK2019: Verweis auf nicht aufgelöstes externes Symbol ""public: __thiscall Test::~Test(void)" (??1Test@@QAE@XZ)" in Funktion "_main" .
debug\Wth.exe:-1: 错误:LNK1120: 2 nicht aufgelöste Externe
我有一个非常简单的类测试:
test.h
#ifndef TEST_H
#define TEST_H
#include <QtCore/QObject>
class Test
{
public:
Test(QString name);
~Test();
private:
QString m_name;
};
#endif // TEST_H
那么 .cpp 文件如下所示:
test.cpp
#include "test.h"
Test::Test(QString st) : m_name(st){}
Test::~Test(){}
非常基本,在我的主要功能中:
main.cpp
#include <QCoreApplication>
#include "test.h"
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
Test t("lam");
return a.exec();
}
【问题讨论】:
-
什么不起作用?
-
sry,我已经发布了错误消息,上面写着:引用未解析的外部符号
-
你确定 test.cpp 文件被编译了吗?
-
也许你应该重建你的代码。请在重建之前运行 qmake 并清理项目,