Problem using Windows library in Qt



  • When I compile my projects, "LNK2019: unresolved external symbol" appears. Function names like GetPixel, GetDC, ReleaseDC, SetCursorPos appear so I am sure it is to do with the Windows library.

    The project itself shouldn't have problem. I think it is because I have recently reinstalled Qt. What should I do to resolve this issue?



  • Hi,

    The error message you have given is very generic. If the function names you mentioned appear in the error messages, then those function names doesn't look like Qt's. Qt's classes start with Q, functions with q and member functions with lower-case letters. You need to link to the library that contains those functions.



  • Thanks. But still I don't know how should I perform it.

    I tried to copy to files in "Microsoft Visual Studio 12.0\VC\lib" and paste them in "Qt\5.4\msvc2013\lib" and "Qt\5.4\msvc2013_64\lib" respectively.

    When I compile my project with Qt 5.4.0 MSVC 2013 32bit, the linking errors are still there. And with Qt 5.4.0 MSVC 2013 64bit, the errors reduced to one new error: LNK1112: module machine type 'X86' conflicts with target machine type 'x64'.


  • Moderators

    you need to specifiy explicitly against which windows libs you want to link.
    This can e.g. be done in your .pro file. If you've already done it and wondering why it's not working then rerun qmake on it.



  • So, I added the following codes to the .pro:

    @LIBS += -L"J:/Program Files (x86)/Windows Kits/8.1/Lib/winv6.3/um/x64"

    OTHER_FILES +=
    kernel32.lib
    user32.lib
    gdi32.lib
    winspool.lib
    comdlg32.lib
    advapi32.lib
    shell32.lib
    ole32.lib
    oleaut32.lib
    uuid.lib
    odbc32.lib
    odbccp32.lib@

    Nothing changed when I build it with Qt 5.4.0 MSVC 2013 64bit.
    And more link errors appeared when I build with Qt 5.4.0 MSVC 2013 32bit...
    What should I do???


  • Moderators

    OTHER_FILES doesn't correspond to the linked libs!
    Also it shouldn't be necessary to specify the full path to the libs, since they should already be known to the compiler.

    Read "this":http://doc.qt.digia.com/qtcreator-2.1/creator-project-qmake-libraries.html to let QtCreator do the work.

    Or do the following changes (and rerun qmake afterwards):
    @
    LIBS += -lkernel32 -lkernel32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -luuid -lodbc32 -lodbccp32
    @



  • [quote author="raven-worx" date="1422265475"]OTHER_FILES doesn't correspond to the linked libs!
    Also it shouldn't be necessary to specify the full path to the libs, since they should already be known to the compiler.

    Read "this":http://doc.qt.digia.com/qtcreator-2.1/creator-project-qmake-libraries.html to let QtCreator do the work.

    Or do the following changes (and rerun qmake afterwards):
    @
    LIBS += -lkernel32 -lkernel32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -luuid -lodbc32 -lodbccp32
    @[/quote]

    OH!!! Thanks! Thanks! You saved my day!

    Your method works. But there is a mistake, you typed -lkernel32 twice and missed -luser32. Nevertheless, you have pointed the way for me. Thanks!


Log in to reply
 

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