:-1: error: LNK1104: cannot open file 'kernel32.lib'



  • When I tried to compile a console application in Qt [latest] I get this error:
    :-1: error: LNK1104: cannot open file 'kernel32.lib'
    What can I do to fix this error?



  • by the way, my .pro looks like this:

    QT += core
    QT -= gui

    CONFIG += c++11
    WIN32:LIBS += C:/Program Files (x86)/Windows Kits/10/Lib/10.0.10586.0/um/x64/kernel32.lib
    INCLUDEPATH += C:/Users/Del Noble/Documents/Dev/c++/abc

    TARGET = JME_Test
    CONFIG += console
    CONFIG -= app_bundle

    TEMPLATE = app

    SOURCES += main.cpp


  • Qt Champions 2016

    @Papa
    Hello,
    This snippet should suit you:

    # This will only work on windows in any case, so specifying a platform seems redundant
    LIBS += -L"C:/Program Files (x86)/Windows Kits/10/Lib/10.0.10586.0/um/x64/" -lkernel32 
    

    Why you'd want to link kernel32, however, is beyond my abilities to comprehend.

    Kind regards.



  • Thanks kshegunov, now my pro looks like this:
    QT += core
    QT -= gui

    CONFIG += c++11
    WIN32:LIBS += C:/Program Files (x86)/Windows Kits/10/Lib/10.0.10586.0/um/x64/kernel32.lib
    LIBS += -LC:/Program Files (x86)/Windows Kits/10/Lib/10.0.10586.0/um/x64/ -lkernel32
    INCLUDEPATH += C:/Users/Del Noble/Documents/Dev/c++/jme

    TARGET = JME_Test
    CONFIG += console
    CONFIG -= app_bundle

    TEMPLATE = app

    SOURCES += main.cpp

    ---- However, I am still getting the same error.


  • Qt Champions 2016

    @Papa
    Hello,
    You either use WIN32:LIBS or LIBS not both with the same argument(s). Because you're trying to link a very basic system library that is available only on windows, and presumably, you intend to use some platform specific functions, it's a good bet you won't be running your app on other platforms. This is why I said that specifying the OS seemed redundant. Additionally you must quote your path (as done in my example), because it contains spaces.

    Kind regards.



  • OK, now it looks like this:
    QT += core
    QT -= gui

    CONFIG += c++11
    WIN32:LIBS += C:/Program Files (x86)/Windows Kits/10/Lib/10.0.10586.0/um/x64/shell32.lib
    WIN32:LIBS += C:/Program Files (x86)/Windows Kits/10/Lib/10.0.10586.0/um/x64/ -lkernel32.lib
    WIN32:LIBS += -LC:/Program Files (x86)/Windows Kits/10/Lib/10.0.10586.0/um/x64/ -lkernel32
    INCLUDEPATH += C:/Users/Del Noble/Documents/Dev/c++/jme

    TARGET = JME_Test
    CONFIG += console
    CONFIG -= app_bundle

    TEMPLATE = app

    SOURCES += main.cpp

    --- However, the problem remains


  • Qt Champions 2016

    @Papa
    Hello,
    I don't understand why you didn't do as I suggested, perhaps I hadn't explained myself clearly? Your .pro file should look something like this (note the the quoted paths):

    # ... Some stuff
    
    CONFIG += c++11
    win32  {  #< This only spares me to write win32:LIBS at every line
        # You must use quoted paths when they contain spaces
        LIBS += "C:/Program Files (x86)/Windows Kits/10/Lib/10.0.10586.0/um/x64/kernel32.lib"
        LIBS += "C:/Program Files (x86)/Windows Kits/10/Lib/10.0.10586.0/um/x64/shell32.lib" 
    }
    # Again, use quoted paths
    INCLUDEPATH += "C:/Users/Del Noble/Documents/Dev/c++/jme"
    
    # ... More stuff
    

    Here you can find more information on the LIBS qmake variable.

    Kind regards.



  • Hi @Papa ,

    Few days back I have the same problem. It has nothing to do with Qt. It is problem caused by the MVSC. In my machine, I have both MSVC 2013 and 2008. When I updated the MVSC 2013, it caused this issue for Qt 4.8 2008(This is only in my case). But all Qt project works fine in Visual studio with Qt plugin. I have this problem only with Qt creator with MSVC compiler. And I am sure, it has nothing to do with Qt.

    • In my case, reinstalling MSVC worked perfectly. If possible, try this. I tried many but did not work except this.
    • Don't need to reinstall all VS versions. Just reinstall only the compiler you have problem.In my case, i have problem with only VS 2008, I reinstalled only VS 2008.

    Seems, this problem happens mostly when you have multiple MSVC's like 2008 12 13 on your machine. I have this issue on Windows10.

    -> Sorry for mutliple edits for this reply.



  • @kshegunov
    I don't wanna link against anything, all I want to do is debug and/or run the program, it is Qt that needs to use the C++ linker and compiler. How it compiles and what it links to is not of my concern, as I said, all I want to do is write my program and run it, and if needed debug it.
    I am a newbie, so advance programming is not for me yet.



  • @kshegunov
    Yes you were right, thanks so much.
    However, Qt now says:
    :-1: error: LNK1158: cannot run 'rc.exe'

    Following the pattern you showed me, I added this line to the pro file:
    LIB += "C:/Program Files (x86)/Windows Kits/10/bin/x64/rc.exe"
    but to no avail.

    How can I solve this problem, is Qt always this complicated?
    Would it be easier of I use g++ instead of VC++?



  • Hi @Papa ,

    Copy this file from "c:\Program Files (x86)\Windows Kits\8.1\bin\x86\” to “c:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\”.

    Use Qt plugin in VS then you can compile all Qt work without this error. You will get compile error only in Creator. Seems it is the error caused because of different bit versions. Seems Qt misunderstood the compiler version.Reinstalling VS will fix all these errors automatically for you. It might take hardly 15 minuten. You can save lot of time.

    How can I solve this problem, is Qt always this complicated?

    No, Qt is very friendly than VS if you are making Qt projects. It is error from compiler.


  • Qt Champions 2016

    @Ni.Sumi said:

    Copy this file from "c:\Program Files (x86)\Windows Kits\8.1\bin\x86\” to “c:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\”.

    This is bad advice. You shouldn't go around copying files to make things "work".

    Use Qt plugin in VS then you can compile all Qt work without this error.

    This is good advice, provided you work with visual studio.

    @Papa
    Are you using QtCreator? You shouldn't need to link the kernel32, shell32 and the like, it sound as a simple configuration error. Make sure you've created a kit that matches the (presumably) downloaded Qt distribution.
    Here are a few links that should help you get started:
    http://doc.qt.io/qtcreator/index.html
    http://doc.qt.io/qtcreator/creator-configuring.html
    http://doc.qt.io/qtcreator/creator-tool-chains.html
    http://doc.qt.io/qtcreator/creator-targets.html
    http://doc.qt.io/qtcreator/creator-project-qmake.html

    If you have configured everything properly you wouldn't need to link the system libraries and shouldn't have problems running the resource compiler (rc.exe). If you're building from the command line, then it's a different matter.

    I don't wanna link against anything, all I want to do is debug and/or run the program, it is Qt that needs to use the C++ linker and compiler. How it compiles and what it links to is not of my concern, as I said, all I want to do is write my program and run it, and if needed debug it.

    You're wrong about this. You will be needing some basic knowledge what the compiler and linker do, possibly the loader and this has nothing to do with Qt. You, as a programmer, have to know how a program is built at least to the point to recognize what errors you get and why.

    Kind regards.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.