Cannot load dll with QLibrary using Qt5
-
@Tiago-M-Pinto said in Cannot load dll with QLibrary using Qt5:
If yes, the DLLs can only be loaded with an executable compiled with MSVC, right?
Usually,
extern "C"
means the DLL can be loaded with any executable compiled with any C/C++ compiler.Since I am using minGW compiler, If it was used to compile the DLLs, could I solve my problem?
The best way to find out is to try it.
The DLLs have some functions that I need to use. My goal is to upgrade my program with no need to compile it again if new DLLs are available (the functions prototypes won't change). Is there any other library that I could use instead of QLibrary?
It doesn't sound like you need a library to use the DLL. Just add the header and library to your *.pro file, and then
#include
the header in your .cpp code and call the function directly!Example: If you have these files...
- C:\my3rdpartystuff\include\foo.h
- C:\my3rdpartystuff\bin\foo.dll
...then add this to your *.pro file:
INCLUDEPATH += "C:/my3rdpartystuff/include" LIBS += -L"C:/my3rdpartystuff/bin" -lfoo
[EDIT: Trailing slashes removed from the 2 lines above]
If there are any problems, the compiler and linker will tell you.
wrote on 5 Mar 2020, 16:54 last edited by@JKSH just one more thing:
I couldn't add my DLL as you said but all worked out by adding the library using Qt Creator interface (in "Add Library..." -> "External Library") which asks for the .a file and the include path.
-
@JKSH, that is a very good post!
Just one addition:
INCLUDEPATH += "C:/my3rdpartystuff/include/"
LIBS += -L"C:/my3rdpartystuff/bin/" -lfooIt might be useful to omit the trailing slashes for the directories.
INCLUDEPATH += "C:/my3rdpartystuff/include" LIBS += -L"C:/my3rdpartystuff/bin" -lfoo
On Windows these are converted to backslashes and can cause problems on line ends, for example.
Regards
@Tiago-M-Pinto said in Cannot load dll with QLibrary using Qt5:
I compiled a simple DLL using minGW and it finally worked using QLibrary.
...
I couldn't add my DLL as you said but all worked out by adding the library using Qt Creator interface (in "Add Library..." -> "External Library") which asks for the .a file and the include path.
Sounds like you got it to work in 2 different ways. Congrats, and happy coding!
@aha_1980 said in Cannot load dll with QLibrary using Qt5:
It might be useful to omit the trailing slashes for the directories.
...
On Windows these are converted to backslashes and can cause problems on line ends, for example.
Edited, thanks!
21/22