I have a dll which is some kind of plugin and I intend to deploy it as a package, the dll and all it's dependencies (also dlls) in one package. The issue that I have is that the dll is checking for it's dependencies in the exe folder instead of its own folder, its dependencies are next to it.
Is there a way to tell it where the dependencies are?
Edit: In my case the plugin is loaded by QPluginLoader and the answers hinted that this is relevant as the loader decides where to look for dependencies.
CodePudding user response:
From the documentation:
Note that the standard search strategy and the alternate search strategy specified by
LoadLibraryExwithLOAD_WITH_ALTERED_SEARCH_PATHdiffer in just one way: The standard search begins in the calling application's directory, and the alternate search begins in the directory of the executable module thatLoadLibraryExis loading.
This is exactly the behavior you described. You cannot change this behavior from the build system (in re: the [cmake] tag), but will need to modify the application's plugin-loading logic.
CodePudding user response:
As @Alex Reinking pointed out the loader is responsible for finding the dlls, in my case the loading was done by QPluginLoader and a solution was to set the current directory to the plugin directory as the loader looks in the current directory for dlls:
QDir pluginsDir(QLatin1String("../src/"));
QDir::setCurrent(pluginsDir.path());
QPluginLoader pluginLoader(pluginsDir.absoluteFilePath(fileName));
