[英]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? 及其后续行动?
Define the TMP environment variable under project Properties > C/C++ Build > Environment. 在项目属性> C / C ++构建>环境下定义TMP环境变量。
Credit to http://avr-eclipse.sourceforge.net/wiki/index.php/Known_Issues#Error:_.27This_application_has_requested_the_Runtime_to_terminate_it_in_an_unusual_way..27 感谢http://avr-eclipse.sourceforge.net/wiki/index.php/Known_Issues#Error:_.27This_application_has_requested_the_Runtime_to_terminate_it_in_in_an_unusual_way..27
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.