简体   繁体   English

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

[英]MinGW - Application terminates in unusual way (after finishing) once a .dll was loaded

I have a problem with dynamically loading shared libraries on Windows when compiling with Cygwin's MinGW. 使用Cygwin的MinGW进行编译时,我在Windows上动态加载共享库时遇到问题。

The application consists of 6 parts: 2 static libraries, 3 shared libraries and 1 executable that uses the static libraries and loads the shared libraries at runtime. 该应用程序包括6个部分:2个静态库,3个共享库和1个使用静态库并在运行时加载共享库的可执行文件。

I'm using the i686-pc-mingw32-g++ in Cygwin. 我在Cygwin中使用i686-pc-mingw32-g++ All source files are compiled with the -std=c++11 flag and them linked like this: 所有源文件都使用-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

The application runs fine and does what expected, but once the program has finished its execution and returns from the main method, I get the message: 该应用程序可以正常运行,并且可以完成预期的工作,但是一旦程序完成执行并从main方法返回,我将收到以下消息:

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

This only occurs when I load one of the shared libaries; 仅当我加载共享库之一时才会发生这种情况。 if I don't, the application terminates without the message. 如果我不这样做,则应用程序将终止而不显示该消息。

I suspect that this program is related to Windows' LoadLibrary ; 我怀疑该程序与Windows的LoadLibrary I also tried freeing each library manually before returning from main, but the same problem occurs. 我还尝试过手动释放每个库,然后再从main返回,但是发生相同的问题。

Note: the message does not occur and everything works as expected when compiling with Cygwin's GCC using the same code. 注意:使用Cygwin的GCC使用相同的代码进行编译时,不会出现该消息,并且一切都会按预期工作。

Any help is greatly appreciated. 任何帮助是极大的赞赏。

EDIT: Found one more thing: when I'm linking the binary without "-static", it doesn't crash. 编辑:发现了另一件事:当我链接没有“ -static”的二进制文件时,它不会崩溃。

I've seen something similar, reported before: http://thread.gmane.org/gmane.comp.gnu.mingw.user/41724 我见过类似的东西,之前曾报道过: http : //thread.gmane.org/gmane.comp.gnu.mingw.user/41724

Could this be applicable in your case? 这是否适用于您的情况? In particular: http://thread.gmane.org/gmane.comp.gnu.mingw.user/41724/focus=41738 特别是: http : //thread.gmane.org/gmane.comp.gnu.mingw.user/41724/focus=41738

and its follow-up? 及其后续行动?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Cygwin编译错误:“此应用程序已请求运行时以不寻常的方式终止它” - Cygwin compiling error: “this application has requested the runtime to terminate it in an unusual way” “此应用程序已请求运行时以异常方式终止它”的原因是什么? - What is the cause of “This application has requested the Runtime to terminate it in an unusual way”? 此应用程序已请求Runtime以不寻常的方式终止它。 - This application has requested the Runtime to terminate it in an unusual way. MinGW,链接到Windows上的DLL - MinGW, linking to a dll on Windows 用mingw准备lapack dll - preparing lapack dll with mingw 我可以加载一个dll,以便在加载时删除它吗? - Can I load a dll in such a way that it can be deleted while it's loaded? Windows DLL在同一个应用程序中意外加载了多次 - Windows DLL unexpectedly loading more than once in the same application 使用MinGW进行C ++的DLL管理? - DLL management for C++ with MinGW? 如何在C程序中捕获此“此应用程序已请求运行时以异常方式终止它”错误? - How can I catch this “This application has requested the Runtime to terminate it in an unusual way” error in my C program? 完成脚本后关闭PC - shutdown PC after finishing a script
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM