从第三方 DLL 调用 Qt 中的函数在调试模式下工作,在发布模式下崩溃
我使用第三方 DLL (FTD2xx) 与外部设备通信。使用 Qt4,在调试模式下一切正常,但在成功完成被调用函数后,发布会默默崩溃。它似乎在返回时崩溃,但是如果我在函数末尾向控制台(使用 qDebug)写入一些内容,有时它不会在那里崩溃,而是在几行或几十行之后崩溃。
我怀疑堆栈没有正确清理,调试版本可以幸存,但发布版本会被它阻塞。有人遇到过类似的问题吗? DLL 本身无法更改,因为源代码不可用。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看来降低优化级别是唯一的方法。 DLL 本身可能存在问题,因为如果打开优化,除了从该 DLL 调用单个函数之外不执行任何操作的程序也会以同样的方式崩溃。
幸运的是,优化级别的变化所造成的大小和速度损失可以忽略不计。
编辑:对于在 Qt 5.0 或更高版本上遇到类似问题的任何人:如果您更改优化级别(例如,更改为
QMAKE_CXXFLAGS_RELEASE = -O0
),通常仅仅更改优化级别是不够的重建应用程序。需要完整的“全部清理”。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.请注意 - EPANET 库不是线程安全的,它包含很多全局变量。
您是否从不同的线程调用该库的两个方法?
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?