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. Add DLL paths at runtime
Forum Updated to NodeBB v4.3 + New Features

Add DLL paths at runtime

Scheduled Pinned Locked Moved Unsolved General and Desktop
cmakedllwindows
4 Posts 2 Posters 3.8k Views
  • 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
    Maluna34
    wrote on last edited by
    #1

    Hello,

    In a CMake project, I have 2 different output folders for library files and executable files (unit tests).

    set(EXECUTABLE_OUTPUT_PATH "${PROJECT_SOURCE_DIR}/../bin")
    set(LIBRARY_OUTPUT_PATH "${PROJECT_SOURCE_DIR}/../lib")
    

    On Linux, the path to lib folder is needed to build unit tests, but not at runtime. But if I'm not wrong, on Windows, we also need the path where to search DLLs for at runtime. To do this it's possible to add the lib folder in the Windows PATH.

    But I figured out that Qt Creator is able to run an executable without adding the path of Qt DLLs in Windows PATH, or copying Qt DLLs next to the exe. It seems that it's able to add a kind of runtime path to find DLLs, no?

    Is it possible to do that for my project? Or the only two solutions are to output all binaries to the same folder, or add the lib folder to the Windows PATH?

    Sorry for not being very clear about all of that. Thank you for your help!!

    1 Reply Last reply
    0
    • hskoglundH Offline
      hskoglundH Offline
      hskoglund
      wrote on last edited by
      #2

      Hi, while Qt Creator is a fine piece of software, it's no magician. it just does a putenv()** to add the path to your Qt DLLs to the PATH env. variable before launching your .exe file.
      For example, for MSVC2019, it takes the PATH setting from the Build Settings, prepends it with C:\Qt\5.15.2\msvc2019\bin;, then runs the .exe file.

      1 Reply Last reply
      3
      • M Offline
        M Offline
        Maluna34
        wrote on last edited by Maluna34
        #3

        Indeed, thanks a lot!!

        I would like to know: currently I'm adding missing paths manually for each exe in run environment (app + each unit tests).
        Is there a way to do it for all the targets or through the .pro file?
        Maybe with LIBS += -LMyPath or QMAKE_RPATHDIR is more suitable?

        1 Reply Last reply
        0
        • hskoglundH Offline
          hskoglundH Offline
          hskoglund
          wrote on last edited by
          #4

          Do you mean how to add paths so that your .exe files can be run from Qt Creator, or adding paths so that your .exe files can be run without Qt Creator?

          In the first case (starting .exe files from Qt Creator) as long as you only have a single version of Qt installed on your PC, there should be no need to add any paths, as I said earlier, Qt Creator adds the path to the Qt dlls for you.

          In the second case (starting .exe files without Qt Creator) then there are 2 ways to do it:

          1. copy the Qt dlls to the same directory that your .exe file is in, either manually or by using the windeployqt.exe program
          2. adding the path to the Qt dlls to the PATH env. variable

          Note: LIBS += -LMyPath has no effect on runtime lookup of .dlls or .so files
          QMAKE_RPATHDIR has no effect on Windows, because Windows does not support adding a list of paths to your .exe/elf file where to find the Qt dlls/so files (works only on Linux and MacOS)
          Also on Linux, QMAKE_RPATHDIR is not needed for the first case (starting .exe/elf files from Qt Creator) since Qt Creator does that automatically for you (by issuing a linker command e.g. -Wl,-rpath,/home/user/Qt/5.15.2/gcc_64/lib)

          1 Reply Last reply
          1

          • Login

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