Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt fails to open shell32.lib even when included

Tags:

qt

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.

like image 329
BenK Avatar asked Mar 18 '23 06:03

BenK


1 Answers

I found a solution. Open the Projects tab on the left pane, and:

  1. Add all desired library paths to the LIB variable
  2. Add the path for sc.exe (in the Windows SDK/bin folder) to PATH
  3. Rebuild.

So apparently putting LIBS += in the .pro file just doesn't work in my Qt, although INCLUDEPATH+= for headers does. Oh well.

like image 74
BenK Avatar answered Mar 23 '23 18:03

BenK