【问题标题】:Visual Studio 2010 Qt Link ProblemVisual Studio 2010 Qt 链接问题
【发布时间】:2011-08-29 14:50:18
【问题描述】:

我花了一个周末试图解决这个问题,我已经走到了最后一步。我的目标:让 Visual Studio 2010 和 Qt 4.7.3 一起工作。

我从源代码安装了 Qt,并指定使用以下配置进行构建:

configure.exe -debug-and-release -opensource -platform win32-msvc2010 -no-webkit -no-phonon -no-phonon-backend -no-script -no-scripttools -no-qt3support -no-multimedia -没有ltcg

配置后,我跑了nmake,没问题。

在我的 Visual Studio 2010 解决方案中,我有两个项目。 它抱怨它无法链接 Qt 库。在通用属性中

AssetIO 最初是使用 Qt IDE 构建的,我使用 Visual Studio 中的 Qt 插件来导入项目。编译项目 AssetIO 工作得很好。但是,编译 Short 项目会导致以下链接器错误: 右键单击 Short 项目,选择属性。我添加了 AssetIO 作为参考。单击配置属性,VC++ 目录,我添加了以下包含目录:

这是我为该项目拥有的库文件: 而不是发布更多的屏幕截图,我的 AssetIO 项目的包含目录是: C:\qt_source\4.7.3\include

我的 AssetIO 项目的库目录是: C:\qt_source\4.7.3\bin

这是我正在尝试开始工作的项目的简单源代码(我的简单测试项目)

main.cpp
int main(int argc, char* argv[])
{
    AssetIO::LevelLoader a;
    a.dostuff();

    return 0;
}

LevelLoader.h

#ifndef LEVELLOADER_HPP
#define LEVELLOADER_HPP

namespace AssetIO
{
    class LevelLoader {
    public:
        explicit LevelLoader();
        ~LevelLoader();

        void dostuff();
    };
}

#endif // LEVELLOADER_HPP

LevelLoader.cpp

#include "LevelLoader.hpp"
#include <QDomDocument>
#include <QFile>
#include <QDebug>
#include <QString>

using namespace AssetIO;

enum ComponentType { Drawable = 0, Position };

// This will definitely be changed, to return a full-blown component. Passing the tagname directly to the
// component factory.
ComponentType ConvertToComponentType(QString tagName)
{
if(tagName.toLower() == "Drawable") {
    return Drawable;
}
else if(tagName.toLower() == "Position") {
    return Position;
}
else {
    // LOG
    exit(EXIT_FAILURE);
}
}

LevelLoader::LevelLoader()
{
}

LevelLoader::~LevelLoader()
{
}

void LevelLoader::dostuff()
{
QDomDocument doc("la");
QFile file("../../../Resources/input.sto");

if(!file.open(QIODevice::ReadOnly)) {
    // TODO: log this, something
    exit(EXIT_FAILURE);
}

if( !doc.setContent(&file)) {
    // TODO: log
    file.close();
}
// we close the file now the doc has control (i think)
file.close();

// Read the root element
QDomElement root = doc.documentElement();
if(root.tagName() != "Root") {
    // TODO: log
    exit(EXIT_FAILURE);
}

// Read the Header Info
QDomNode headerNode = root.firstChild();

QDomElement e = headerNode.toElement();
if(e.tagName().toLower() != "HeaderInfo") {
    // LOG
}

QDomNodeList componentNode = headerNode.childNodes();
int s = componentNode.count();

QString componentTag(componentNode.at(0).toElement().tagName());
QDomNamedNodeMap a = componentNode.at(0).attributes();
}

我无法弄清楚我做错了什么。有没有人有任何想法?我到处寻找解决方案。

【问题讨论】:

    标签: c++ visual-studio-2010 qt linker


    【解决方案1】:

    你是不是忘了指定 VS 链接的 Qt lib 文件?您可能需要 QtCored4.lib、QtGuid4.lib(d 代表“调试”,在发布配置中将其删除),也许还需要其他一些。如果给您带来麻烦的项目是 .exe 应用程序 - 转到它的 Properties->Linker->Command Line 并添加 {Qored4.lib QtGuid4.lib} 不带括号。

    P。 S.我的建议:首先,在Qt Creator中创建一个项目并进行测试。然后运行 ​​qmake -tp vc -r - 你会得到一个适用于 VS 或任何其他主要平台的完美解决方案。此外,Creator 有一个不错的编辑器,你可能会喜欢。

    【讨论】:

    • 我让它工作了,通过运行带有命令参数的 qmake,你的意思是从命令行正确吗?我打算用Qt作为编辑器,很好用。我只是想在 Visual Studio 2010 中调试 exe 时能够进入我的assetIO 项目。
    【解决方案2】:

    我发现你的库目录丢失了 C:\qt_source\4.7.3\lib ,包括它。

    然后包含

    QtCored4.lib QtGuid4.lib 和任何其他 Qt 库

    正如紫罗兰色长颈鹿建议的那样。您还需要使用“发布版本”来执行此操作

    QtCore4.lib QtGui4.lib 和任何其他 Qt 库

    简历

    【讨论】:

      【解决方案3】:

      如果你创建了Qt 类QDomDocument 的实例。可能需要添加 "QtXml4.lib" 。请在 Visual Studio 中添加这个库,即Project-&gt;properties-&gt;Linker-&gt;Input====&gt; Additional Dependencies。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-05-27
        • 1970-01-01
        • 2012-08-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多