Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

delayed DLL loading possible when using QMake?

In my project, I have a set of DLLs I want to load delayed, i.e. on first use instead of on process start. That means I want to use /DELAYLOAD flag of the MSVC linker (see [1] for more explanation) for certain DLLs (not Qt itself). The reason is that some users experience crashes during DLL initilization (which we can't reproduce). A former non-Qt version of the software didn't have that problem, but it used delayed loading, so that might make a difference.

Using QMake, I found no way to get delayed loading to work. Does anyone know how to pass /DELAYLOAD to the msvc linker, using qmake features on bypassing qmake?

[1] http://www.codeproject.com/KB/DLL/Delay_Loading_Dll.aspx

like image 405
Frank Osterfeld Avatar asked Jun 25 '10 07:06

Frank Osterfeld


2 Answers

Modify .pro file:

## Make delayed load possible. If your project is itself a DLL which uses xxx.dll, you
## also need to include this line in the applications that use your DLL.
LIBS += DelayImp.lib

## Specify that xxx.dll loading needs to be delayed
win32:CONFIG(release, debug|release) {
    QMAKE_LFLAGS_RELEASE += /DELAYLOAD:xxx.dll
} else:win32:CONFIG(debug, debug|release) {
    QMAKE_LFLAGS_DEBUG += /DELAYLOAD:xxx.dll
}

I use Qt5.1.1 with MSVC 2012, but according to MS this should work from VC2005 and up.

like image 81
Marc Avatar answered Oct 30 '22 20:10

Marc


You ought to be able to just add it to one of the QMAKE_LFLAGS variables such as QMAKE_LFLAGS_RELEASE. This would be in the project file that is responsible for linking your dll to your application (presumably the one that creates the final application).

Something like

win32 {
    QMAKE_LFLAGS_RELEASE+=/DELAYLOAD:MyDll.dll
}

should work.

like image 21
Troubadour Avatar answered Oct 30 '22 20:10

Troubadour