Exceptions not caught when linking static libs

匆匆过客 提交于 2021-01-28 06:10:32

问题


I started implementing a try/catch in my program, but when I was testing it, the exceptions were never caught and the program just crashes. Even the simplest use case of a try/catch would fail, i.e

try
{
    throw 123;
}
catch (...)
{
    cerr << "This line doesn't get hit." << endl;
}

After lots of digging around researching how exceptions work and debugging, I finally found that the issue was because I was linking with specifically -static-libstdc++ which was causing the break. The exceptions work fine when this flag isn't set. After further research I found this bug report, but I can't really figure out what the status is on it. It appears that the issue is still at large, but according to this earlier bug report it seems that there might be a work around according to the comments. Unfortunately I don't understand exactly what all the comments mean and what they did to get it to work if at all outside of building GCC manually (which I'd like to avoid if I can).

Is there a way to resolve this bug while still linking the static standard lib and how would I go about it?

来源:https://stackoverflow.com/questions/50779224/exceptions-not-caught-when-linking-static-libs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!