Reputation: 333
I have a QT 5.4 project compiling with MSVC2013 64 bit that throws the linker error LNK1104: cannot open file 'shell32.lib'. Every Qt Widgets app on Windows requires this library.
This error is thrown regardless of whether a path to that lib is specified, and if I include some other library, I get no error for that library, which leads me to believe that the Qt Creator is automatically looking for shell32 in a location specified somewhere other than the .pro file.
The .pro file looks like this.
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = test
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
win32:CONFIG(release, debug|release): LIBS += $$quote(C:/Program Files (x86)/Microsoft SDKs/Windows/v7.1A/Lib/shell32.lib)
else:win32:CONFIG(debug, debug|release): LIBS += $$quote(C:/Program Files (x86)/Microsoft SDKs/Windows/v7.1A/Lib/shell32.lib)
INCLUDEPATH += $$quote(C:/Program Files (x86)/Microsoft SDKs/Windows/v7.1A/Include)
DEPENDPATH += $$quote(C:/Program Files (x86)/Microsoft SDKs/Windows/v7.1A/Include)
Not sure if this is relevant, but shell32.lib is one of the libraries listed under the QMAKE_LIBS_CORE variable in qmake.conf.
SOLUTION
In the Projects tab on the left pane, add the desired library paths to the LIB variable, and add the path to SC.exe (also in the Windows SDK) to the PATH variable. The latter is necessary or else you get "LNK 1158: can't execute rc.exe." Apparently the LIBS += statement in my .pro doesn't work, although INCLUDEPATH += does (I get "can't find windows.h" when it's removed).
I don't know why the LIBS+= doesn't work or why I also need the path to RC.exe (I never had to add it using Visual Studio), but at least there is a solution.
Upvotes: 4
Views: 12831
Reputation: 3998
use it like this
win32:CONFIG(release, debug|release): LIBS += -L$$quote(C:/Program Files (x86)/Microsoft SDKs/Windows/v7.0A/Lib/) -lshell32
else:win32:CONFIG(debug, debug|release): LIBS += -L$$quote(C:/Program Files (x86)/Microsoft SDKs/Windows/v7.0A/Lib/) -lshell32
INCLUDEPATH += $$quote(C:/Program Files (x86)/Microsoft SDKs/Windows/v7.0A/Include)
DEPENDPATH += $$quote(C:/Program Files (x86)/Microsoft SDKs/Windows/v7.0A/Include)
Make sure you run qmake after making changes to the .pro file
this could be auto generated by right clicking the project in the left panel then select menu item "Add Library"
Then select "External Library"
Then select Static Library for windows and browse your path to select the path for the shell32.lib and include folder
Again make sure that you run qmake before you compile this project
this could be found in the projects menu .The same menu you found the "Add Library" option
Upvotes: 2
Reputation: 333
I found a solution. Open the Projects tab on the left pane, and:
So apparently putting LIBS += in the .pro file just doesn't work in my Qt, although INCLUDEPATH+= for headers does. Oh well.
Upvotes: 3