Qt移动构造函数链接错误
Qt move constructor linking error
我正在尝试在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库。
相关文章:
- Netbeans 10:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)
- CMake 错误:链接器命令失败,退出代码为 1 和 cpp.o 文件
- clang:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用) - 体系结构的未定义符号 x86_64:
- 如何修复 clang: 错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)
- Android NDK.Build命令失败.未定义的引用.clang++:错误:链接器命令失败,退出代码为1
- 使用cmake错误链接boost日志
- 错误:链接器命令失败,退出代码为 1(使用 -v 查看调用):在 Macbook 上
- C++ XCODE ld:找不到体系结构x86_64 clang 的符号:错误:链接器命令失败,退出代码为 1(使用 -
- clang:错误:链接器命令失败,C++代码中的退出代码为 1(使用 -v 查看调用)
- 静态库中的 g++ 错误链接函数
- 未定义的参考错误链接天然函数Android
- C++编译错误:ld:找不到体系结构x86_64 clang 的符号:错误:链接器命令失败,退出代码为 1(使用 -v
- QT Q_PROPERTY错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)
- ld:找不到体系结构x86_64 clang 的符号:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)
- OSX MOJAVE -LD:架构X86_64 clang找不到符号:错误:链接器命令失败,出口代码1
- C 错误链接器命令失败了出口代码1(使用-V查看调用)
- LD:架构x86_64 clang找不到符号:错误:链接器命令失败,出口代码1(使用-v to See
- 聚输出错误 - 链接列表
- Xcode链接器错误:链接器命令失败,退出代码为1(使用-v查看调用)
- 尝试构建C DLIB示例无法与数百个未定义的参考错误链接