std::bad_cast 崩溃似乎与 boost_regex 有关

发布于 2024-09-24 02:27:39 字数 4482 浏览 1 评论 0原文

我已经在 Ubuntu 上编译了完全相同的代码,现在正在尝试让我的程序在 MacOS 10.6.4 上运行。我使用 ./bootstrap.sh 以 root 身份安装了 boost 1.4.4

,然后 ./bjam

我还执行了以下操作: ./bjam installvariant=debugdefine=_GLIBCXX_DEBUG --with-regex

我使用 Codeblocks 编译了程序(没有任何错误),但是当我运行程序时,出现以下错误:

$ ./CWT_PD
terminate called after throwing an instance of 'std::bad_cast'
  what():  std::bad_cast
Abort trap

当我使用控制台查看错误时,我看到以下错误

Thread 0 Crashed:  Dispatch queue: com.apple.main-thread
0   libSystem.B.dylib               0x00007fff837c33d6 __kill + 10
1   libSystem.B.dylib               0x00007fff83863972 abort + 83
2   libstdc++.6.dylib               0x00007fff826785d2 __tcf_0 + 0
3   libstdc++.6.dylib               0x00007fff82676ae1 __cxxabiv1::__terminate(void (*)()) + 11
4   libstdc++.6.dylib               0x00007fff82676b16 __cxxabiv1::__unexpected(void (*)()) + 0
5   libstdc++.6.dylib               0x00007fff82676bfc __gxx_exception_cleanup(_Unwind_Reason_Code, _Unwind_Exception*) + 0
6   libstdc++.6.dylib               0x00007fff8263293f std::__throw_bad_alloc() + 0
7   libboost_regex.dylib            0x00000001000d04b8 std::collate<char> const& std::use_facet<std::collate<char> >(std::locale const&) + 85 (locale_facets.tcc:117)
8   libboost_regex.dylib            0x00000001000a8794 boost::re_detail::cpp_regex_traits_base<char>::imbue(std::locale const&) + 124 (cpp_regex_traits.hpp:218)
9   libboost_regex.dylib            0x00000001000dae35 boost::re_detail::cpp_regex_traits_base<char>::cpp_regex_traits_base(std::locale const&) + 43 (cpp_regex_traits.hpp:173)
10  libboost_regex.dylib            0x00000001000dae83 boost::shared_ptr<boost::re_detail::cpp_regex_traits_implementation<char> const> boost::re_detail::create_cpp_regex_traits<char>(std::locale const&) + 30 (cpp_regex_traits.hpp:852)
11  libboost_regex.dylib            0x00000001000daeed boost::cpp_regex_traits<char>::cpp_regex_traits() + 35 (cpp_regex_traits.hpp:872)
12  libboost_regex.dylib            0x00000001000daf33 boost::regex_traits<char, boost::cpp_regex_traits<char> >::regex_traits() + 21 (regex_traits.hpp:75)
13  libboost_regex.dylib            0x00000001000daf4b boost::regex_traits_wrapper<boost::regex_traits<char, boost::cpp_regex_traits<char> > >::regex_traits_wrapper() + 21 (regex_traits.hpp:169)
14  libboost_regex.dylib            0x00000001000daf8d boost::re_detail::regex_data<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::regex_data() + 63 (basic_regex.hpp:212)
15  libboost_regex.dylib            0x00000001000db041 boost::re_detail::basic_regex_implementation<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::basic_regex_implementation() + 21 (basic_regex.hpp:248)
16  libboost_regex.dylib            0x00000001000a8815 boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::do_assign(char const*, char const*, unsigned int) + 75 (basic_regex.hpp:698)
17  CWT_PD                          0x000000010000b9bc mzxml::Reader::read_index_offset() + 92
18  CWT_PD                          0x00000001000056cb main + 2571
19  CWT_PD                          0x0000000100001698 start + 52


Binary Images:
       0x100000000 -        0x10003dfe7 +CWT_PD ??? (???) <0C453159-591D-862F-B273-7450BCF7E4D5> /Users/dspiciarich/Desktop/B/CWT_PD_fast/bin/Release/CWT_PD
       0x10005b000 -        0x1001ecfef +libboost_regex.dylib ??? (???) <F0FCDDDF-8C65-D0CA-33D9-93D50CDE0DD7> /usr/local/lib/libboost_regex.dylib
    0x7fff5fc00000 -     0x7fff5fc3bdef  dyld 132.1 (???) <B536F2F1-9DF1-3B6C-1C2C-9075EA219A06> /usr/lib/dyld
    0x7fff81aad000 -     0x7fff81ab1ff7  libmathCommon.A.dylib 315.0.0 (compatibility 1.0.0) <95718673-FEEE-B6ED-B127-BCDBDB60D4E5> /usr/lib/system/libmathCommon.A.dylib
    0x7fff8262c000 -     0x7fff826a9fef  libstdc++.6.dylib 7.9.0 (compatibility 7.0.0) <35ECA411-2C08-FD7D-11B1-1B7A04921A5C> /usr/lib/libstdc++.6.dylib
    0x7fff83774000 -     0x7fff83934fef  libSystem.B.dylib 125.2.0 (compatibility 1.0.0) <95E02DD0-ADEA-745B-E7FA-ABA064E4658C> /usr/lib/libSystem.B.dylib
    0x7fffffe00000 -     0x7fffffe01fff  libSystem.B.dylib ??? (???) <95E02DD0-ADEA-745B-E7FA-ABA064E4658C> /usr/lib/libSystem.B.dylib

我将非常感谢任何人可以提供的帮助。

谢谢你, 大卫

I've gotten the exact same code compiled on Ubuntu and am now trying to get my program working on a MacOS 10.6.4. I installed boost 1.4.4 as root using

./bootstrap.sh and then
./bjam

I also performed the following:
./bjam install variant=debug define=_GLIBCXX_DEBUG --with-regex

I compiled the program using Codeblocks (without any errors) but when I run the program I get the following error:

$ ./CWT_PD
terminate called after throwing an instance of 'std::bad_cast'
  what():  std::bad_cast
Abort trap

When I look into the error using Console, I see the following error

Thread 0 Crashed:  Dispatch queue: com.apple.main-thread
0   libSystem.B.dylib               0x00007fff837c33d6 __kill + 10
1   libSystem.B.dylib               0x00007fff83863972 abort + 83
2   libstdc++.6.dylib               0x00007fff826785d2 __tcf_0 + 0
3   libstdc++.6.dylib               0x00007fff82676ae1 __cxxabiv1::__terminate(void (*)()) + 11
4   libstdc++.6.dylib               0x00007fff82676b16 __cxxabiv1::__unexpected(void (*)()) + 0
5   libstdc++.6.dylib               0x00007fff82676bfc __gxx_exception_cleanup(_Unwind_Reason_Code, _Unwind_Exception*) + 0
6   libstdc++.6.dylib               0x00007fff8263293f std::__throw_bad_alloc() + 0
7   libboost_regex.dylib            0x00000001000d04b8 std::collate<char> const& std::use_facet<std::collate<char> >(std::locale const&) + 85 (locale_facets.tcc:117)
8   libboost_regex.dylib            0x00000001000a8794 boost::re_detail::cpp_regex_traits_base<char>::imbue(std::locale const&) + 124 (cpp_regex_traits.hpp:218)
9   libboost_regex.dylib            0x00000001000dae35 boost::re_detail::cpp_regex_traits_base<char>::cpp_regex_traits_base(std::locale const&) + 43 (cpp_regex_traits.hpp:173)
10  libboost_regex.dylib            0x00000001000dae83 boost::shared_ptr<boost::re_detail::cpp_regex_traits_implementation<char> const> boost::re_detail::create_cpp_regex_traits<char>(std::locale const&) + 30 (cpp_regex_traits.hpp:852)
11  libboost_regex.dylib            0x00000001000daeed boost::cpp_regex_traits<char>::cpp_regex_traits() + 35 (cpp_regex_traits.hpp:872)
12  libboost_regex.dylib            0x00000001000daf33 boost::regex_traits<char, boost::cpp_regex_traits<char> >::regex_traits() + 21 (regex_traits.hpp:75)
13  libboost_regex.dylib            0x00000001000daf4b boost::regex_traits_wrapper<boost::regex_traits<char, boost::cpp_regex_traits<char> > >::regex_traits_wrapper() + 21 (regex_traits.hpp:169)
14  libboost_regex.dylib            0x00000001000daf8d boost::re_detail::regex_data<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::regex_data() + 63 (basic_regex.hpp:212)
15  libboost_regex.dylib            0x00000001000db041 boost::re_detail::basic_regex_implementation<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::basic_regex_implementation() + 21 (basic_regex.hpp:248)
16  libboost_regex.dylib            0x00000001000a8815 boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::do_assign(char const*, char const*, unsigned int) + 75 (basic_regex.hpp:698)
17  CWT_PD                          0x000000010000b9bc mzxml::Reader::read_index_offset() + 92
18  CWT_PD                          0x00000001000056cb main + 2571
19  CWT_PD                          0x0000000100001698 start + 52


Binary Images:
       0x100000000 -        0x10003dfe7 +CWT_PD ??? (???) <0C453159-591D-862F-B273-7450BCF7E4D5> /Users/dspiciarich/Desktop/B/CWT_PD_fast/bin/Release/CWT_PD
       0x10005b000 -        0x1001ecfef +libboost_regex.dylib ??? (???) <F0FCDDDF-8C65-D0CA-33D9-93D50CDE0DD7> /usr/local/lib/libboost_regex.dylib
    0x7fff5fc00000 -     0x7fff5fc3bdef  dyld 132.1 (???) <B536F2F1-9DF1-3B6C-1C2C-9075EA219A06> /usr/lib/dyld
    0x7fff81aad000 -     0x7fff81ab1ff7  libmathCommon.A.dylib 315.0.0 (compatibility 1.0.0) <95718673-FEEE-B6ED-B127-BCDBDB60D4E5> /usr/lib/system/libmathCommon.A.dylib
    0x7fff8262c000 -     0x7fff826a9fef  libstdc++.6.dylib 7.9.0 (compatibility 7.0.0) <35ECA411-2C08-FD7D-11B1-1B7A04921A5C> /usr/lib/libstdc++.6.dylib
    0x7fff83774000 -     0x7fff83934fef  libSystem.B.dylib 125.2.0 (compatibility 1.0.0) <95E02DD0-ADEA-745B-E7FA-ABA064E4658C> /usr/lib/libSystem.B.dylib
    0x7fffffe00000 -     0x7fffffe01fff  libSystem.B.dylib ??? (???) <95E02DD0-ADEA-745B-E7FA-ABA064E4658C> /usr/lib/libSystem.B.dylib

I would be so appreciative of any help anyone could provide.

Thank you,
David

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

扭转时空 2024-10-01 02:27:39

这看起来很老,但当我构建一个与 libstdc++ 静态链接并在 Ubuntu 18.04 上升压的程序时,我遇到了同样的问题,尝试在 CentOS 7 上运行,我相信由于不同的 c++ 可能会发生类似的问题操作系统上的运行时。

据我通过调试和阅读相关问题了解到,当调用 CentOS 上已经存在的 c++ 运行时符号而不是我的程序中的符号时,就会发生崩溃。

有效的解决方案是使用 -Wl,--exclude-libs,ALL gcc 链接器标志隐藏程序中使用的静态库的符号

,当然,如果您不想,可以自定义隐藏所有静态库。

参考文献:

https://stackoverflow.com/a/35675938/3673564

如何将 -fvisibility 选项应用于静态库中的符号?

this seems very old but I just had the same exact issue when I built a program that is linked statically against libstdc++ and boost on Ubuntu 18.04, tried to run in it on CentOS 7, I believe issues like that can happen due to the different c++ runtimes on operating systems.

As far as I understood from debugging and reading about related issues, the crash happens when symbols from the c++ runtime already present on CentOS get called instead of the ones that are inside my program.

The solution that worked was hiding the symbols of static libraries used in my program using

-Wl,--exclude-libs,ALL gcc linker flag, of course this can be customized if you don't want to hide all static libraries.

refs:

https://stackoverflow.com/a/35675938/3673564

How to apply -fvisibility option to symbols in static libraries?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文