Important: Please read the Qt Code of Conduct -

Add DLL paths at runtime

  • Hello,

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


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

  • 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.

  • 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?

Log in to reply