Nominate our 2022 Qt Champions!

Link error: can't open shell32.lib, which I added to project

  • I'm using Qt 5.4 with Qt Creator and MSVC 12.0 as the compiler (Desktop Qt 5.4.0 MSVC2013 64bit)

    I'm new to Qt and worked through the textFinder example. When I built it, I got a linker error "can't find shell32.lib"
    This file is in the Windows SDK, so I followed the steps to "add a library":
    and added it as a static system library, did a clean and rebuild, but got the same error again.

    Trying the same thing but including it as an external library and explicitly giving the full shell32.lib path and the includes directory for the Windows SDK also failed.

    What gives?

    Also, I'm not so clear on what an "internal library" is. The description there says it adds a library in your build tree. But if the library is already in the build tree, then why do you have to add it?

    It occurred to me that perhaps the Qt Creator needs file permissions to open this file. If so, how do I grant them?

    Any help is much appreciated!

  • Hi, actually shell32.lib should be difficult to get rid of (not the other way around :-). What I mean is, every Qt app you build on Windows uses shell32.lib.

    For example, a simple test of shell32.lib is to display the same dialog box that is shown when type winver in a CMD window:

    1. Create a new Widgets app.
    2. in mainwindow.cpp. add #include "windows" after #include "ui_mainwindow.h"
    3. also in mainwindow.cpp, after ui->setupUi(this); add this line:
      ShellAbout(NULL,QString("Hello from Qt").toStdWString().c_str(),NULL,NULL);
      Now run the app, the dialog box from Windows is shown, or?

  • That's interesting, but it doesn't really answer my question. The problem, again, is that the linker fails to find/open shell32.lib even when I explicitly add it to the libraries for my project. So I think something may not be configured correctly but I don't know what.

    FWIW, see the last post on "this thread":
    I have both the windows 7 and 8 SDKs. The Windows 8 SDKs are installed in a folder called Windows Kits. I still fail to open shell32.lib with the 8.0 SDK, for both the x64 and x86 versions. And the Qt Creator program has full rights since I am running as admin. There is no LIB environment variable set on my system.

    I have also tried using quotes because the file path has spaces in it, "as under LIBS here":
    but also to no avail.

    The code looks like this:
    @win32:CONFIG(release, debug|release): LIBS += $$quote(C:/Program Files (x86)/Windows Kits/8.0/Lib/win8/um/x64/shell32.lib)
    else:win32:CONFIG(debug, debug|release): LIBS += $$quote(C:/Program Files (x86)/Windows Kits/8.0/Lib/win8/um/x64/shell32.lib)

    INCLUDEPATH += $$quote(C:/Program Files (x86)/Windows Kits/8.0/Include)
    DEPENDPATH += $$quote(C:/Program Files (x86)/Windows Kits/8.0/Include)

    But remember, I still get "cannot open shell32.lib" even without this code. It's as if this code to add the library does nothing at all.

  • Hmm, on my computer (Win7 SP1 64-bit, MSVC2013 Update 4 and Qt 5.4) Qt uses the shell32.lib in the Windows Kit 8.1 folder (C:\Program Files (x86)\Windows Kits\8.1\Lib\winv6.3\um\x64). Not the 8.0 folder :-(
    If I remove shell32.lib from my 8.1 folder Qt gives me the same LNK1104 error as you get.

    To see if your Qt installation is broken or not, that's why I suggested a simple test as in my previous post, if you get the LNK1104 error for that program, then next step would be to look at your MSVC2013 installation.

  • On my computer, the shell32.lib is in the 8.0 folder (I also have the Windows 7 SDK, which is in Windows SDKS/7,0A). The 8.1 folder has only a few files.
    Anyway, what difference does it make where the lib is? It's the same file.

    I have used my MSVC installation before, linking to Windows 7 SDK libraries.. I don't believe it has been updated but it works fine.

    I'll try your test, though.

    Can't find "windows.h" This also happened when I attempted to compile and run one of the examples.
    To clarify, that line you asked me to write, with the ShellAbout function, goes in the constructor after ui->setupUi(this)? What does it do?

  • Fixed this a while back. The issue was that including headers in the .pro file is not enough (I was under the impression that it was). The relevant libraries also need to be added in the project settings.

  • Thanks Benk10 for the input. However, could you please show the line to add to the .pro file? In my case, since I am using Win10, my shell32.lib is located in the folder called 'C:\Program Files (x86)\Windows Kits\10\Lib\10.0.10586.0\um\x64'

    Thanks so much for the help.

  • @Papa Hello.
    I also met this problem today.But I can't find this file under'C:\Program Files (x86)\Windows Kits\10\Lib\10.0.10586.0\um\x64'.I tried reinstall WDK,however it's useless.I'm still looking for solution.

  • Go to PowerShell, or cmd, and type this
    dir C:\Program" "Files" (x86)"\Windows" "Kits\10\Lib\10.0.10586.0\um\x64\shell32.lib > C:\tmp\shell32_lib_verification.txt

    Open the file created; you should have something like this

    Directory: C:\Program Files (x86)\Windows Kits\10\Lib\10.0.10586.0\um\x64

    Mode LastWriteTime Length Name
    -a---- 2015-11-19 9:04 PM 260368 shell32.lib

    Keep posting, for good or bad, the forum will do its best to help you.

  • This post is deleted!

Log in to reply