Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Unable to load plugins by QPluginLoader because of unavailability of shared libraries
I am deploying an application where I have a "Plugins" folder and all the dependent shared libraries are kept in the Plugins folder.
When I run the program, I get the following error, "Cannot load library $library_name. The specified module could not be found".
The reason for this is because, the shared libraries aren't in the application directory path and hence the plugins aren't successful in loading.
I've tried all possible solutions like qputenv, qt.conf and addLibraryPath, but was not successful. Please anyone can guide me for the following or can i consider the solution of placing allthe plugins and shared libraries in the executable folder.
Hi and welcome to devnet,
What version of Qt are you using ?
On what OS ?
Where are the dependencies located ?
How are you deploying your application ?
- QT version : 5.7
- Windows 7
- AppFolder contains app.exe
--Plugins contains Viewer.dll(plugin), and other dependent dlls.
I want to add the AppFolder/Plugins folder to PATH variable at runtime. I tried using qputenv, qt.conf and addLibraryPath ways of doing but eventually the the same runtime error comes.
Can you show your .pro file ?
Did you check with a tool like Dependency Walker to check if you have anything missing ?
Yes I checked with dependency walker. I resolved those dependencies by placing all the libraries in the AppFolder/Plugins directory where the Viewer.dll exists. Still I was facing the same issue. Eventually I had to remove all the dependencies of Viewer.dll and put in the AppFolder.
From this what I understand is even if the shared libraries for a plugin are in a separate directory from the AppFolder, it will not work. They have to be put in the AppFolder to work.
Now my question all remains the same.
How do we add this AppFolder/Plugins to PATH variable at runtime so that the folders other than AppFolder are recognized by the application?
@SGaist . Hope you understand I cannot share the .pro file.
Take a look at QCoreApplication::addLibraryPath. Looks like what you need.
@SGaist I tried the same as mentioned earlier. It even adds to the PATH variable when printed with "QString QCoreApplication::applicationDirPath()". But it seems that the Application is not able to recognize the added directory to PATH once the QApplication instance is created. I tried placing the statement "QCoreApplication::addLibraryPath" before the instance is created, but it gives error that first the QApplication instance must be created which is very much true.
My library "Viewer.dll" is loaded by QPluginLoader.
Did you try to call it before QCoreApplication instance is created?
@jsulm Yes I tried to call before the QCoreApplication instance is created. But i get the error to first instantiate the QCoreApplication and then add the library path.
Secondly I did it after the instance is created, and after printing the latest library paths, I could see there. But eventually the run time error "Cannot load library $library_name. The specified module could not be found" still persists.
This MSDN entry might be of interest.