Load shared library: The specified module could not be found
-
I'm developing a C++ cross-platform application and a shared library to be loaded in this main application.
Both projects compile and run Ok in Ubuntu 20.04 and Mac OSX Catalina. All good!
In Windows environment, I compile both projects without errors or warnings.
But, when I open my main app and try to load the
shared library
I got this run-time error:Cannot load library C:\Users\VM\Desktop\build-lobular-bearing-plugin-Qt6-Debug\libLobular-Bearing-Plugin.dll: The specified module could not be found .:
1 - Why this is happen in Windows-only environment?
2 - How can I fix it?Obs.: To load the shared library, I'm using the
QLibrary
class.- Windows 10 x64
- Qt 6.0.1
- Qt Creator IDE 4.14.0
-
@fem_dev said in Load shared library: The specified module could not be found:
a) No...I'am always running the main app using Qt Creator IDE
your problem is that the dependency library (libjsonfortran.dll) cannot be found when you load "libLobular-Bearing-Plugin.dll" with QLIbrary. This is done by the OS which looks in certain paths for libaries.
So either put the dll file next to your exe (which is in this case in QtCreators build folder) or update the PATH variable (can be done in the PROJECTS tab -> Run settings in QtCreator) with the folder containing the dll.
When you release your exe you should anyway bundle the dependency libraries - probably next to the exe - afterall.Also i assume you are using mingw as compiler? If so you should be able to point to the .a file explicitly in the linking definition. (To choose between static and dynamic version of the lib)
-
Hi
this is when you run standalone?
Did you check it has the compiler runtime included in the deplyment folder ? -
@mrjj I found where is the problem, but I don't know how to solve it.
Answer your questions:
a) No...I'am always running themain app
using Qt Creator IDE
b) As you can see below, I think that it another problem...The problem is only one CMakeLists.txt line.
I'm using a library calledjson-fortran
, that I compilled and installed in my Windows 10 system.When I compile the
shared library
using this first line below, it works great and mymain app
can load thisshared library
without any error.TARGET_LINK_DIRECTORIES(${PROJECT_NAME} PUBLIC "C:/Users/VM/Downloads/json-fortran/build/lib")
As you can see, I cloned the repo in my
Downloads
folder...but I also installed the library files in myProgram Files
folder using:make install
.
All the files are there too.BUT, if I switch this line to:
TARGET_LINK_DIRECTORIES(${PROJECT_NAME} PUBLIC "C:/Program Files (x86)/jsonfortran-gnu-8.2.1/lib")
The
shared library
project compiles Ok, no errors too. But when mymain app
tries to load it, I got this run-time error:Cannot load library C:\Users\VM\Desktop\build-lobular-bearing-plugin-Qt6-Debug\libLobular-Bearing-Plugin.dll: The specified module could not be found .:
In both cases I got a clean and no error/warning compilation.
Could you help me?
Thank you,
UPDATE 1
I already tried to include
back slashs
in the path to skip spaces...but doesn't work too...UPDATE 2
This problem only occurs in Windows environment
UPDATE 3
I found a parcial solution:
In the installed library folder, I have 2 files:libjsonfortran.a
andlibjsonfortran.dll.a
If I delete thedll
version...theshared library
compilation get the.a
static file and works good.So, How can I instruct the CMake to use always the static version only?
-
Hi,
This cmake thread might help.
Or the quick and dirty is to install the static and shared libraries in separate folders.
-
@fem_dev said in Load shared library: The specified module could not be found:
a) No...I'am always running the main app using Qt Creator IDE
your problem is that the dependency library (libjsonfortran.dll) cannot be found when you load "libLobular-Bearing-Plugin.dll" with QLIbrary. This is done by the OS which looks in certain paths for libaries.
So either put the dll file next to your exe (which is in this case in QtCreators build folder) or update the PATH variable (can be done in the PROJECTS tab -> Run settings in QtCreator) with the folder containing the dll.
When you release your exe you should anyway bundle the dependency libraries - probably next to the exe - afterall.Also i assume you are using mingw as compiler? If so you should be able to point to the .a file explicitly in the linking definition. (To choose between static and dynamic version of the lib)