The standalone Qt application fails to execute the functions in the dynamic library.
-
Hi
My PC environment is Windows XP 32bit.
I compiled the static library of Qt 5.5.1 and then successfully build the standalone application.
The standalone application is going to load a dynamic library via "LoadLibrary" and launch each function via "GetProcAddress".
If I put the application into different directory, some functions of the dynamic library fails to be executed.
Thanks for any suggestion.
-
Hello @Nospy,
If I put the application into different directory, some functions of the dynamic library fails to be executed.
Have you tried to debug your application? Did you make sure the library is loaded and the symbols' addresses are resolved correctly by
GetProcAddress
? On a related note, why not link against the library instead of resolving at runtime?Kind regards.
-
Thanks for your reply.
Yes, I checked the symbols' address are correct.
Besides, I'm worried about the implementation of the library maybe change in the future so
resolving it at runtime and don't need to compile the application again.
Allow me to tell more for understanding the question.
The dynamic library has three functions, Fun_A, Fun_B and Fun_C.
The standalone application will link the library at runtime.
Case 1) I put the application into C:. It's fine. Fun_A, Fun_B and Fun_C can be executed.
Case 2) I put the same application into C:\xxxxxx. Fun_A and Fun_B can be executed but Fun_C can't.
Case 3) I revised the source code. For example, adding qDebug() to print the information. After
recompiling the application, Fun_A can be executed but Fun_B can't.p.s. I confirmed again the symbol's addresses are correct in these cases.
Thanks again.
-
Is this dynamic library also linked to the static Qt?
It seems its also using Qt?Normally with static Qt it wants plugins as static also
http://doc.qt.io/qt-5/plugins-howto.html#static-plugins
"Plugins can be linked statically into your application. If you build the static version of Qt, this is the only option for including Qt's predefined plugins"I guess this only applies to predefined plugins?
-
@Nospy said:
Besides, I'm worried about the implementation of the library maybe change in the future so resolving it at runtime and don't need to compile the application again.
This is why libraries are made binary compatible, plus I'm assuming you're resolving symbols with C-linkage, which is already binary compatible, so if the implementation changes you shouldn't really care
Case 1) I put the application into C:. It's fine. Fun_A, Fun_B and Fun_C can be executed.
Case 2) I put the same application into C:\xxxxxx. Fun_A and Fun_B can be executed but Fun_C can't.
Case 3) I revised the source code. For example, adding qDebug() to print the information. After
recompiling the application, Fun_A can be executed but Fun_B can't.By "can't be executed" you mean you get a segmentation fault? Are you sure
LoadLibrary
isn't loading some other version of thedll
, one from the system location for example? -
@kshegunov said:
@Nospy said:
Besides, I'm worried about the implementation of the library maybe change in the future so resolving it at runtime and don't need to compile the application again.
This is why libraries are made binary compatible, plus I'm assuming you're resolving symbols with C-linkage, which is already binary compatible, so if the implementation changes you shouldn't really care
Yes, you are right.
Case 1) I put the application into C:. It's fine. Fun_A, Fun_B and Fun_C can be executed.
Case 2) I put the same application into C:\xxxxxx. Fun_A and Fun_B can be executed but Fun_C can't.
Case 3) I revised the source code. For example, adding qDebug() to print the information. After
recompiling the application, Fun_A can be executed but Fun_B can't.By "can't be executed" you mean you get a segmentation fault? Are you sure
LoadLibrary
isn't loading some other version of thedll
, one from the system location for example?Yes, I got a segmentation fault. There is only one version of the dll.
Base on @mrjj's reply, I make a workaround solution, let the QT application to execute another application doing the job which the dll does.
Thank a lot. @mrjj and @kshegunov