gpt4 book ai didi

windows - MinGW - 加载 .dll 后,应用程序以异常方式终止(完成后)

转载 作者:可可西里 更新时间:2023-11-01 10:45:23 25 4
gpt4 key购买 nike

在使用 Cygwin 的 MinGW 进行编译时,我在 Windows 上动态加载共享库时遇到问题。

该应用程序由 6 个部分组成:2 个静态库、3 个共享库和 1 个使用静态库并在运行时加载共享库的可执行文件。

我在 Cygwin 中使用 i686-pc-mingw32-g++。所有源文件都使用 -std=c++11 标志进行编译,它们的链接如下:

Static libraries:
i686-pc-mingw32-ar rcs libxxx.a bin/*.o
i686-pc-mingw32-ar rcs libyyy.a bin/*.o

Each shared library:
i686-pc-mingw32-g++ -fPIC -shared -o ###.dll bin/*.o -lxxx -L../xxx -lyyy -L../yyy

Executable:
i686-pc-mingw32-g++ -o program.exe bin/*.o -lxxx -L../xxx -lyyy -L../yyy -static

应用程序运行良好并按预期执行,但是一旦程序完成执行并从 main 方法返回,我收到消息:

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.

这仅在我加载其中一个共享库时发生;如果我不这样做,应用程序将在没有消息的情况下终止。

我怀疑这个程序与Windows的LoadLibrary有关;我也尝试在从 main 返回之前手动释放每个库,但出现了同样的问题。

注意:当使用相同的代码使用 Cygwin 的 GCC 进行编译时,不会出现该消息并且一切都按预期工作。

非常感谢任何帮助。

编辑:又发现一件事:当我在没有“-static”的情况下链接二进制文件时,它不会崩溃。

最佳答案

我以前看过类似的报道: http://thread.gmane.org/gmane.comp.gnu.mingw.user/41724

这是否适用于您的情况?特别是: http://thread.gmane.org/gmane.comp.gnu.mingw.user/41724/focus=41738

及其后续行动?

关于windows - MinGW - 加载 .dll 后,应用程序以异常方式终止(完成后),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28810454/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com