Qt移动构造函数链接错误

Qt move constructor linking error

本文关键字:错误 链接 构造函数 移动 Qt      更新时间:2023-10-16

我正在尝试在Visual Studio 2010中编译一个项目,使用Qt 4.8.4。

当我构建它时,我获得链接器错误,如下所示:

error LNK2001: external symbol "__declspec(dllimport) public: class QByteArray & __thiscall QByteArray::operator=(class QByteArray &&)" (__imp_??4QByteArray@@QAEAAV0@$$QAV0@@Z) not resolved
error LNK2001: external symbol "__declspec(dllimport) public: class QString & __thiscall QSTring::operator=(class QString &&)" (__imp_??QString@@QAEAAV0@$$QAV0@@Z) not resolved

你可以在链接器中看到移动构造函数,但我没有使用任何c++ 11特性。

链接器错误出现在文件中,我有这样的代码:

QByteArray xTmpArray;
QString    xString;
...
xTmpArray = xString.toAscii();

如果我注释了赋值行,链接错误就会消失(对于QString赋值也是一样)。

如何消除这些链接错误?

我解决了。这(自然)是一个链接问题,因为他们给了我用Visual Studio 2008编译的库,不支持移动构造函数。我使用了正确的版本,用VS2010编译,一切正常。

我写了下面的代码:

#include <QString>
#include <QByteArray>
int main() {
    QString s("a");
    QByteArray ba = s.toAscii();
    return 0;
}

我正在用命令编译它:

g++ -I /usr/include/qt4/QtCore/ -I/usr/include/qt4/ qtuse.cpp -lQtCore -o qtuse

我没有问题。你好像忘了把你的程序和QtCore链接起来。

检查项目设置。你应该添加Qt的lib目录到链接路径。

Microsoft Visual Studio 2015中去:

(Project properties)->General->Platform Toolset

设置为visual studio 2013 (v120)

这对我来说很有用:)

当MSVC和预构建的Qt二进制文件之间存在版本不匹配时,会发生此错误。不要那样做。

如果你正在使用MSVC2015,你需要链接到预构建MSVC2015 Qt库。

相关文章: