9

So as the question title says, i'm specifically wondering how to include the path to a .dll file in the actually project file. I know it's the better practice to include the dll file with the project file, but i'd still just like to know if it's possible to be done?

Currently my .pro file consists of the following;

QT       += core gui

TARGET = Test
TEMPLATE = app

win32 {
    INCLUDEPATH += "D:/Projects/Build Output/include/"

    CONFIG(debug, debug|release) {
        LIBS += "D:/Projects/Build Output/libs/debug/myLib.lib"
        LIBS += "D:/Projects/Build Output/bin/x86 debug/myLib.dll"
    } 
    else {
        LIBS += "D:/Projects/Build Output/libs/release/myLib.lib"
        LIBS += "D:/Projects/Build Output/bin/x86 release/myLib.dll"
    }
}

SOURCES += main.cpp\
    mainwindow.cpp

HEADERS  += mainwindow.h

FORMS    += mainwindow.ui

Would be cool, just to know that it can be done, thanks in advance for your help :).

Danran
  • 471
  • 1
  • 7
  • 21

3 Answers3

4

If you mean you want the generated exe can find its dependant dll files automatically upon you run it, then it cannot be done for implicit dll linking (i.e. linking with .lib files, as in your example). Windows has a fixed search sequence to locate the necessary dll files. None of those sequence can be put into a QT pro file. So the following statement has no effect only makes QT know to search the dll's .lib/.a file in that path:

 LIBS += "D:/Projects/Build Output/bin/x86 debug/myLib.dll"

The closest approach might be defining the dll paths as the macros in the pro file. Then use LoadLibrary to explicitly load dlls from those paths in your c/c++ source file. Of course only if you can settle with explicit linking instead of implicit linking,

Penghe Geng
  • 13,286
  • 5
  • 31
  • 40
  • 1
    Thanks for your answer :). I asked this mainly because i've been watching the voidRealms QT videos on youtube. In his slightly older video he does the above and it worked fine. (That video specifically; http://www.youtube.com/watch?v=9JTooLxhmC0) so i was just curious why it wasn't working for me. *In his video, he does indeed use a shared library like me but i suppose as it being just under 1 year old. Something must have changed? – Danran Sep 08 '12 at 09:17
  • 4
    In 4:20 into the video he manually copied the dll to the directory of exe, that's why it works for him :) – Penghe Geng Sep 08 '12 at 11:47
  • Any chance I can change the `PATH` variable from my app just before it starts to seach for DLLs? – KcFnMi Feb 10 '21 at 04:47
2

You do not need to put the dll path in the .pro file (windows). All you need to do is to put all your external dll files in a directory and add this directory to the path environment variable . (same as the accepted answer). I am adding this here just to mention important fact: RESTART QT CREATOR for this to work in order to reload the new PATH environment variable.

Raiden Core
  • 1,535
  • 12
  • 13
0

You just need to read the manual and do the same: https://doc.qt.io/archives/qt-4.8/qmake-variable-reference.html#libs. The syntax you're using seems correct.

Matteo
  • 1,107
  • 2
  • 27
  • 47
Luca Carlon
  • 9,546
  • 13
  • 59
  • 91