Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

error LINK2019 is resolved when using explicit paths for library path



  • I have two shared libraries. My two libraries are sub-projects on my main project and are ordered, as I have these lines on my main project *.pro file:

    TEMPLATE = subdirs
    CONFIG += ordered
    SUBDIRS += firstlib secondlib standalone
    

    I add the 1st shared library to my 2nd shared library by adding following lines of code to my 2nd library *.pro project file, which works fine on Linux but does NOT work on Windows:

    win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../firstlib/release/ -lfirstlib
    else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../firstlib/debug/ -lfirstlib
    else:unix: LIBS += -L$$OUT_PWD/../firstlib/ -lfirstlib
    
    INCLUDEPATH += $$PWD/../firstlib
    DEPENDPATH += $$PWD/../firstlib
    

    To my surprise, the above lines do NOT work on Windows, and I receive error LINK2019 and other kinds of LINK errors.

    However, when using explicit paths for LIBS on Windows, it works fine:

    win32:CONFIG(release, debug|release): LIBS += "C:\Users\me\repos\build-myapp-Desktop_Qt_5_11_2_MSVC2017_64bit-Release\firstlib\release\firstlib.lib"
    else:win32:CONFIG(debug, debug|release): LIBS += "C:\Users\me\repos\build-myapp-Desktop_Qt_5_11_2_MSVC2017_64bit-Debug\firstlib\debug\firstlib.lib"
    
    INCLUDEPATH += "C:\Users\me\repos\build-myapp-Desktop_Qt_5_11_2_MSVC2017_64bit-Release\firstlib"
    DEPENDPATH += "C:\Users\me\repos\build-myapp-Desktop_Qt_5_11_2_MSVC2017_64bit-Release\firstlib"
    

    Why do I have to use explicit LIBS paths on Windows to make it work?


  • Qt Champions 2017

    I suspect it path issue. It should work without any issue. You are using the backward slashes you should use two slashes "\" or use one forward slash /.

    Also use -L <dirname> to specify the directory and -l <libname> like follows.

    LIBS += -L"C:\Users\me\repos\build-myapp-Desktop_Qt_5_11_2_MSVC2017_64bit-Release\firstlib\release" -lfirstlib


  • Moderators

    Try this:

    LIBS += -L"$$system_path($${OUT_PWD}/../firstlib/release)" -lfirstlib
    


  • @dheerendra I'm not sure why using $$OUT_PWD for LIBS path is NOT working on Windows but it works on Linux? I mean, why this statement is NOT working on Windows:

    LIBS += -L$$OUT_PWD/../firstlib/release/ -lfirstlib
    


  • @sierdzio Thanks! Using $$system_path() for Windows solved my problem:

    win32:CONFIG(release, debug|release): LIBS += -L"$$system_path($$OUT_PWD/../firstlib/release/)" -lfirstlib
    else:win32:CONFIG(debug, debug|release): LIBS += -L"$$system_path($$OUT_PWD/../firstlib/debug/)" -lfirstlib
    else:unix: LIBS += -L$$OUT_PWD/../firstlib/ -lfirstlib
    

    I feel like QtCreator should add $$system_path() automatically when adding a library to a project, I'm not sure why it doesn't!


  • Moderators

    Yea, good idea. Please suggest it on Qt bugtracker.



  • @sierdzio Right. Submitted the bug report here:

    https://bugreports.qt.io/browse/QTBUG-72265


  • Moderators

    Nice, thanks! Voted.



  • Figured out the root cause of the issue: my executable and a dynamically-link library DLL had the same name! I renamed the DLL sub-project, and the problem got resolved!


Log in to reply