【问题标题】:unresolved linker errors for many windows functions in QtQt 中许多 Windows 函数的未解决的链接器错误
【发布时间】:2013-10-12 16:04:05
【问题描述】:

在 Qt 中,我收到许多 Windows 函数(例如 SHGetKnownFolderPath)的未解决的链接器错误

#include "pip.h"
#include "ui_pip.h"
#include <QFileDialog>
#include <QMessageBox>
#include <Objbase.h>
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <algorithm>
#include <QtNetwork/QHostAddress>
#include <shlobj.h>
#include <windows.h>
#include <Shlwapi.h>
#include <Knownfolders.h>

功能:

PWSTR appData = 0;

    if (SUCCEEDED(SHGetKnownFolderPath(FOLDERID_Desktop,
                                   0,
                                   NULL,
                                   &appData)))
{
    wcout << appData << endl;
}

链接器错误:

pip.obj : error LNK2019: unresolved external symbol _SHGetKnownFolderPath@16 
referenced in function "private: void __thiscall pip::on_submitButton_clicked(void)" 
(?on_submitButton_clicked@pip@@AAEXXZ)

我是否需要告诉 QT Shell32.dll 库在哪里或 shlobj.h 的什么地方?

【问题讨论】:

    标签: c++ windows qt


    【解决方案1】:

    您必须将您的项目与实现该符号的 (shell32.lib)链接

    您应该在 .PRO 文件中添加如下内容:

    LIBS += -L"C:\\Path\\Microsoft SDK\\Windows\\v7.1\\Lib" -lshell32
    

    【讨论】:

    • -L 之后的显式路径不是必需的,Qt 无论如何都必须与 Windows 库链接,所以它就在那里。 -lshell32 就足够了。
    猜你喜欢
    • 2011-05-25
    • 1970-01-01
    • 1970-01-01
    • 2012-03-05
    • 2018-10-08
    • 1970-01-01
    • 1970-01-01
    • 2011-07-18
    • 1970-01-01
    相关资源
    最近更新 更多