I am making a Windows DLL in C++, MinGw 4.8. The library internally uses C++ classes and exceptions, but its interface is C-only, ie. no exception is propagated outside the library.
Unfortunately when I compile the library with -static
option, the C++ exceptions are not caught. Even this simple example fails, the exception is not caught and the application is aborted:
try {
throw std::logic_error("Hello World");
} catch (...) {
std::cout << "Exception caught" << std::endl;
}
When I compile the library without -static
command line switch, it works fine. The funny thing is that the older versions of my library used to work even with static linking and now I am quite confused why it stopped working...
I am calling the library from a simple testing C++ application compiled by the same compiler, but I need to make the library compatible also with other compilers/languages.
Please does anybody have a suggestion how to fix this problem?
EDIT: I tried to replace the -static
option by -static-libstdc++ -static-libgcc
options. Now when I remove -static-libgcc
, exception handling works properly.
So my problem is related to static linking of libgcc, but I still cannot figure out why this matters. Any ideas?
EDIT2: When I debug my DLL, it calls _Unwind_RaiseException
function embedded in the DLL. It looks like some kind of ABI incompatibility... Here the people deal with similar issue:
C++ exceptions and the .eh_frame ELF section
Klasyc