【发布时间】:2013-05-08 15:24:40
【问题描述】:
过去几天我一直在研究这个问题,但没有成功。我一直在尝试用 Qt 创建一个图形应用程序。看来我的 LNK2019 应该来自一个未实现的构造函数:
main.obj:-1: error: LNK2019: unresolved external symbol "public: __cdecl ArbObject::ArbObject(class Table *,int *,int,int,int,int,int)" (??
0ArbObject@@QEAA@PEAVTable@@PEAHHHHHH@Z) referenced in function "class std::vector<class ArbObject *,class std::allocator<class ArbObject *> > __cdecl
createArbObjects(class QList<class QStringList> &,class Table *,int &)" (?createArbObjects@@YA?AV?$vector@PEAVArbObject@@V?$allocator@PEAVArbObject@@@std@@@std@@AEAV?
$QList@VQStringList@@@@PEAVTable@@AEAH@Z)
但是,构造函数在那里并在适当的 .cpp 文件中实现。
.h file has this:
ArbObject(Table* tr, int* rgb, int t, int xpos, int ypos, int w, int h);
.cpp file has this:
ArbObject::ArbObject(Table* tr, int* rgb, int t, int xpos, int ypos, int w, int h)
: QWidget((QWidget*)tr), obj_typ(t), xpos(xpos), ypos(ypos),wid(w), hei(h)
{
...
}
我已经包含了我能想到的所有内容。这在我的 Windows 机器上不起作用,但它在我的 Mac 上运行良好。我的问题是,什么样的依赖会导致这种问题?我还可以探索哪些其他途径来解决我的问题?
- 它是基于编译器的吗? MSVC 与 Clang
- 是否在链接过程中都包含不同的文件,因此它可能无法在一个平台上运行,而不是在另一个平台上运行。
编辑:已修复
看看答案!
【问题讨论】:
-
您是否尝试过在 Windows 上使用 MinGW 编译器编译您的应用程序?你使用的是什么版本的 Qt?
-
构造函数应该始终是 __thiscall,而不是 __cdecl。很难看出你是怎么做到的。
-
@HansPassant,这是我在编译器引用的函数中的行 ArbObject *a = new ArbObject(table, RGB, typ, xpos, ypos, width, height);这里的所有值都是整数,除了 table 和 RGB。它也说找不到文件:main.obj。也许它使用的是旧版本的 main.obj 文件,但重建根本不会改变这一点。
-
@Cameron Tinker,我已经设置了 MinGW 编译器,添加了构建工具包并将其设置为默认值,我得到了相同的消息。我正在使用 Qt 5.0.2
标签: windows qt visual-c++