Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. error LINK2019 is resolved when using explicit paths for library path

error LINK2019 is resolved when using explicit paths for library path

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 3 Posters 930 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    m3g1dd
    wrote on last edited by
    #1

    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?

    sierdzioS 1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by dheerendra
      #2

      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

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      M 1 Reply Last reply
      1
      • M m3g1dd

        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?

        sierdzioS Offline
        sierdzioS Offline
        sierdzio
        Moderators
        wrote on last edited by
        #3

        Try this:

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

        (Z(:^

        M 1 Reply Last reply
        2
        • dheerendraD dheerendra

          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

          M Offline
          M Offline
          m3g1dd
          wrote on last edited by
          #4

          @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
          
          1 Reply Last reply
          0
          • sierdzioS sierdzio

            Try this:

            LIBS += -L"$$system_path($${OUT_PWD}/../firstlib/release)" -lfirstlib
            
            M Offline
            M Offline
            m3g1dd
            wrote on last edited by m3g1dd
            #5

            @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!

            1 Reply Last reply
            0
            • sierdzioS Offline
              sierdzioS Offline
              sierdzio
              Moderators
              wrote on last edited by
              #6

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

              (Z(:^

              M 1 Reply Last reply
              2
              • sierdzioS sierdzio

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

                M Offline
                M Offline
                m3g1dd
                wrote on last edited by
                #7

                @sierdzio Right. Submitted the bug report here:

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

                1 Reply Last reply
                0
                • sierdzioS Offline
                  sierdzioS Offline
                  sierdzio
                  Moderators
                  wrote on last edited by
                  #8

                  Nice, thanks! Voted.

                  (Z(:^

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    m3g1dd
                    wrote on last edited by
                    #9

                    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!

                    1 Reply Last reply
                    3

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved