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

时间:2010-09-22 01:16:30

标签: regex boost-regex

我已经在Ubuntu上编写了完全相同的代码,现在我正在努力让我的程序在MacOS 10.6.4上运行。我使用

以root身份安装了boost 1.4.4

./ bootstrap.sh然后 ./bjam

我还执行了以下操作: ./bjam install variant = debug define = _GLIBCXX_DEBUG --with-regex

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

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

当我使用Console查看错误时,我看到以下错误

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

我非常感谢任何人都能提供的任何帮助。

谢谢你, 大卫

1 个答案:

答案 0 :(得分:0)

这似乎很老了,但是当我建立一个与libstdc ++静态链接并在Ubuntu 18.04上增强的程序,并试图在CentOS 7上运行时,我遇到了一个完全相同的问题,我相信这样的问题可能是由于操作系统上不同的c ++运行时。

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

有效的解决方案是使用

隐藏我的程序中使用的静态库的符号

-Wl,--exclude-libs,ALL gcc链接器标志,当然,如果您不想隐藏所有静态库,则可以自定义。

参考:

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

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