views:

33

answers:

1

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

A: 

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.

Troubadour
Hmm, might try that when I work on that project the next time. I tried all kinds of those flags, but I tried to "inject" also the names of the DLLs I wanted to have loaded delayed IIRC. Actually I want only specific DLLS loaded that way, but it probably doesn't hurt to apply it to all of them.
Frank
@Frank: I've updated the answer to add the missing dll name. Looking at the MSDN docs it looks like the name is required so you would have to do it individually for each one.
Troubadour
I think I tried that though. Well, I'll try again (customer project I don't work on continuously).
Frank