Calling functions in Qt from third-party DLL works in debug mode, crashes in release

本秂侑毒 提交于 2019-12-02 16:29:57

问题


I use a third-party DLL (FTD2xx) to communicate with an external device. Using Qt4, in debug mode everything works fine, but the release crashes silently after successfully completing a called function. It seems to crash at return, but if I write something to the console (with qDebug) at the end of the function, sometimes it does not crash there, but a few, or few dozen lines later.

I suspect a not properly cleaned stack, what the debug build can survive, but the release chokes on it. Did someone encounter a similar problem? The DLL itself cannot be changed, as the source is not available.


回答1:


It seems the reduction of the optimization level was the only way around. The DLL itself might have problems, as a program which does nothing but calls a single function from that DLL crashes the same way if optimization is turned on.

Fortunately, the size and speed lost by the change in optimization level is negligible.

Edit: for anyone with similar problems on Qt 5.0 or higher: If you change the optimization level (for example, to QMAKE_CXXFLAGS_RELEASE = -O0), it's usually not enough to just rebuild the application. A full "clean all" is required.




回答2:


Be warned - the EPANET library is not thread safe, it contains a lot of global variables.

Are you calling two methods of that library from different threads?



来源:https://stackoverflow.com/questions/6276225/calling-functions-in-qt-from-third-party-dll-works-in-debug-mode-crashes-in-rel

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!