QLibrary - Not Working in Release
I'm using a
QLibraryinstance to resolve symbols in a 3rd party library.
When debugging, I can happily
resolvesymbols and execute the resolved functions without fail. However, when in release mode, I'm no longer able to call these resolved functions without an exception occurring and the application terminates immediately.
One of the functions which is causing the crash has the following signature:
typedef int (* fnStRg)(LPCSTR, LPCSTR, LPCSTR);
And I resolve this as follows:
QLibrary lib; lib.setFileName("cad.dll"); lib.load(); // All OK so far in both release and debug fnStRg myFunc = (fnStRg)lib.resolve("StRg"); // All still OK in both release and debug myFunc("PARAM1", "PARAM2", "PARAM3"); // All is OK in debug but in release mode, the above function call generates an exception // Commenting out the above line no longer caused an exception
LPCSTRis defined as:
typedef _Null_terminated_ CONST CHAR *LPCSTR, *PCSTR;
And I have tried passing the arguments as
QString("PARAM1").toStdString().c_str()with no success.
fnStRg myFunc = (fnStRg)lib.resolve("StRg");
// All still OK in both release and debug
Hi! First of all, you need to check if the function could actually be resolved, if not,
fnStRg("PARAM1", "PARAM2", "PARAM3");
Eh, no. A call to the resolved function would be:
myFunc("PARAM1", "PARAM2", "PARAM3");.
@Wieland Sorry, I've updated my question to correct the 'myFunc' call - I am actually calling it this way, not how I originally had it.
The function is correctly resolved, I can verify that the resolved address is valid in both debug and release mode
Hi! Did you get this to work in the meantime? Otherwise please try to create a minimal working example (or better: not working example) so we can try to reproduce this.
@Wieland I have just managed to get this working. I started a new
QWidgetsapplication and brought across the code to load the 3rd party library. When I build for release with this new application, everything works fine - I must be doing something silly in my other application.