Windows DLL上的静态链接libgcc [英] Static linking libgcc on Windows DLL

查看:196
本文介绍了Windows DLL上的静态链接libgcc的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用C ++编写Windows DLL。该库仅具有C接口,并且仅使用也具有C接口的标准Windows库。因此,将所有C ++库静态链接到库中似乎很安全,因为仅使用C接口时我并不依赖于C ++ ABI版本。



不幸的是,当我编译库时使用 -static-stdc ++ -static-libgcc ,我的库停止处理异常,当引发某些异常时,DLL调用其静态链接的 _Unwind_RaiseException 函数会中止整个应用程序。



我认为这可能是损坏的 libgtcc.a 所以我尝试更新我的编译器。但是结果与MinGW 4.8和MinGW 6.3相同。



请问有人能解释我这里到底发生了什么吗?



Klasyc

解决方案

感谢RastyX的回答。经过一番研究后,我发现使用 -static-libgcc 编译DLL部分和不使用此开关的应用程序部分(两个部分都使用相同的g ++编译)时,应用程序崩溃。 / p>

还要感谢Ripi2提出的TDM-GCC建议。我尝试了SJLJ和DWARF-2异常处理,并且都可以工作。



总而言之,似乎MinGW的libgcc不喜欢在每个进程中实例化多个实例。就我而言,我在DLL中使用了它的一个副本(静态链接),在应用程序中使用了它的副本,这可能会破坏异常处理。



另一方面,TDM- GCC像网页上所说的那样专注于基本库的静态链接,因此即使没有 -static-stdc ++ -static-libgcc 命令行开关,其生成的二进制文件也仅依赖于Windows库。 (这就是我要的)。异常处理在这里也起作用,因此更改工具链对我来说是正确的方法。


I am writing a Windows DLL in C++. This library has only C interface and uses only standard Windows libraries which also have C interface. Therefore it seems me safe to statically link all C++ libraries into the library because I am not dependent on C++ ABI version when using C interfaces only.

Unfortunately when I compile my library with -static-stdc++ -static-libgcc, my library stops handling exceptions and when some exception is thrown, the DLL calls its statically linked _Unwind_RaiseException function which aborts the whole application.

I thought it could be a corrupted libgtcc.a so I tried to update my compiler. But the result is the same with both MinGW 4.8 and MinGW 6.3.

Please is anybody able to explain me what is really happening here?

Klasyc

解决方案

Thanks RastyX for that simple example in his answer. After some research I found out that the application crashes when I compile DLL part with -static-libgcc and application part without this switch (both parts compiled with the same g++).

Also thanks to Ripi2 for TDM-GCC suggestion. I tried both SJLJ and DWARF-2 exception handling and both work.

To conclude it, it seems MinGW's libgcc does not like when it is instantiated more than once per process. In my case I use one its copy in DLL (linked statically) and one its copy in the application and this probably breaks the exception handling.

On the other hand TDM-GCC focuses on static linking of the basic libraries as its web page says and therefore produces binaries that depend only on Windows libraries even without -static-stdc++ -static-libgcc command line switches (this is what I want). Also the exception handling works here, so changing of the toolchain is the right way for me.

这篇关于Windows DLL上的静态链接libgcc的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆