Qt中许多Windows函数的未解决的链接器错误

时间:2013-10-12 16:04:05

标签: c++ windows qt

在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的内容?

1 个答案:

答案 0 :(得分:2)

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

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

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