简体   繁体   中英

unresolved linker errors for many windows functions in Qt

In Qt, I am getting unresolved linker errors for many windows functions such as 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>

Function:

PWSTR appData = 0;

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

Linker Error:

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)

Do I need to tell QT where the Shell32.dll library is or something for shlobj.h ?

You have to link your project with the library ( shell32.lib ) that implements that symbol!

You should add something like the following to the .PRO file:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM