Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
325 views
in Technique[技术] by (71.8m points)

c++ - QT - Specify DLL path in pro. file

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 :).

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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,


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...