Calling functions in Qt from third-party DLL works

2019-03-05 07:13发布

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.

标签: qt dll release
2条回答
\"骚年 ilove
2楼-- · 2019-03-05 08:01

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.

查看更多
我命由我不由天
3楼-- · 2019-03-05 08:06

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?

查看更多
登录 后发表回答