[Solved] QPluginLoader and plugins loading 3rd party dll: weird search path?
My problem is the following one: I build plugins that I load with QPluginLoader.
It works fine except that one of them is linking with a 3rd part. dll.
And when I load it, it's looking for the dll in the same folder as QTCore4.dll
My files are organized like this:
I would like myPlugin2.dll to look for it's dependencies in /plugins/. Is is possible?
take a look at this "thread":http://developer.qt.nokia.com/forums/viewthread/4128/
I think, you can set it via
[quote author="r2d3" date="1299015415"]take a look at this "thread":http://developer.qt.nokia.com/forums/viewthread/4128/[/quote]2 points:
- applications look for dll in their own path first, why dlls do not look in their own path too?
- the idea behind this plugin architecture was to distribute all my plugins even if users do not have corresponding dll. And corresponding plugins would fail to load, exposing only the available functions.
If I need to pre-load all possibles dlls, I have to move code related to dlls in the main app, and parse plugins_dll names to detect wich external_dll I should preload.
Does not sound like a smart way to solve the issue.
[quote author="Peppy" date="1299015745"]I think, you can set it via
@QApplication::setLibraryPaths();@[/quote]Already tried that, it does not work. I think it is quite understandable because it will set library path for the main app, while the issue is on the plugin's side.
setLibraryPath change the place plugins are searched in. The DLL is loaded by the OS, it searches it in the .EXE directory and in the PATH.
So the solution is to preload it using its fullpath with QLibrary::load before loading the plugin.
Search Path Used by Windows to Locate a DLL: http://msdn.microsoft.com/en-us/library/7d83bc18(v=vs.80).aspx
So another solution is to make the plugin directory the current directory, so the DLL could be found by Windows.
[EDIT: fixed link, Volker]
So change to current directory to the plugin path, this is a more elegant solution.
[quote author="r2d3" date="1299016515"]So change to current directory to the plugin path, this is a more elegant solution.
"QDir::setCurrent":http://doc.qt.nokia.com/latest/qdir.html#setCurrent[/quote]You rock! How did I not think of this? Simple and elegant. Thanks again