QLibrary Error: Cannot load library The specified module could not be found
-
Hi guys,
i am trying to load a dll library that i need for my project.
I have tried to load the library in the following way:QLibrary lib; lib.setFileName(QDir("C:\\the_path\\lib.dll").absolutePath()); lib.load(); error_msg = lib.errorString();
the error_msg string always contains the following:
"Cannot load Library 'C:\the_path\lib.dll': The specified module could not be found."If i dont give it a valid path, it does also give me the same error, so i guess it somehow does not find the dll.
But when i use QFile to open the file, the path works..No idea why it does not work, has anyone had similar issues?
Btw, i use qcreator with cmake, mingw 64Bit and the DLL is also a 64bit DLL.
-
@MichaelH
One possibility: a.DLL
may be there/openable via plainQFile
, but to load successfully viaQLibrary::load()
it must have (not only the correct architecture etc.) any/all its dependency DLLs found and loadable. If they are not found it may well be that the error message you get is "Cannot load Library '...': The specified module could not be found.", when in fact it ought really be "The library was found but could not be loaded because some of its dependencies are missing or incorrect".You can only use whatever the current Windows tool is which used to be called "Dependency Viewer/Walker" if you want to examine the
.DLL
to see whether some of its dependencies are missing. -
Hi,
Did you check that the output of
QDir("C:\\the_path\\lib.dll").absolutePath()
is what you expect ?On a side note, you should use the forward slash notation for your paths. Qt handles the conversion for you while you use the framework and it's less error prone.