Solved How to disable run-time connection of optional libraries?
-
Hello!
A program written using Qt 4.8.6 crashes when the system linker finds the QtXml4.dll library somewhere from another version of Qt and tries to load it. If we put QtXml from the same Qt assembly into the working directory of our program, then everything works fine (for a working directory on Win has a higher priority than paths from PATH). If you make sure that the linker does not find any QtXml4.dll at all (and do not throw anything into the working directory), then everything also works. Apparently QtXml does not link to our program anywhere. DependencyWalker says that no single binaries from the graph of static dependencies from this library also depend. There is a feeling that Qt implements some internal mechanism of dynamic loading of optional libraries. The only way I know how to implement such a system is to explicitly use something like LoadLibrary in the format "if the linker finds somewhere a shared library with the desired name, then load it, otherwise it will be hammered and worked on," but the search by code / documentation / Internet nothing on this topic did not give anything.
I would be very grateful if someone would tell me what I'm doing wrong. Thank you in advance!
-
Hi and welcome to devnet,
What modules is your application using ?
-
I use QtCore, QtGui, QtNetwork, QtScript, QtSvg, Qwt.
-
Then you should check which of these library links to QtXml. The fact that your application doesn't use it doesn't mean it doesn't use something that might rely on in indirectly.
-
@Stepan3.10.1996 said in How to disable run-time connection of optional libraries?:
(for a working directory on Win has a higher priority than paths from PATH).
One good practice to follow is to avoid putting any Qt binaries in your system PATH. Is it feasible for you to remove all traces of Qt from your PATH?
DependencyWalker says that no single binaries from the graph of static dependencies from this library also depend.
By default, Dependency Walker only shows compile-time links. Select Profile -> Start Profiling... (F7) to find the run-time links.
There is a feeling that Qt implements some internal mechanism of dynamic loading of optional libraries.
Yes. The plugin system is one big example: http://doc.qt.io/qt-5/plugins.html (It's both used internally and externally)
-
I solved the problem.
One of the plugins (QtSvg) connected the QtXml4 library. I added QtXml4.dll to the program folder, because only with it the plugin works correctly.
In order to avoid such problems in the future, I put the qt.conf file (http://doc.qt.io/qt-4.8/qt-conf.html) next to the executable and configured it so that Qt does not connect libraries from the system paths (and from somewhere else, except from the folder with the program).Thanks for the tips.