std::cerr on linux with clang++ and libc++ causes SIGABRT

怎甘沉沦 提交于 2019-12-07 16:18:23

问题


I'm trying to get a simple program running on Ubuntu 12.04 x64 compiled with clang++ 3.3 libc++ libc++abi .

Program:

#include <iostream>
int main(int argc, char **argv) {
  try {
    std::cerr << "Test cerr \n";
  } catch (...) {
    std::cout << "catch exception";
  }
  return 0;
}

Writing to std::cerr prints the message, but results in SIGABRT.

However, writing to std::cout works fine.

Here the ldd output of the executable:

$ldd cerr_test
linux-vdso.so.1 =>  (0x00007fffce5ff000)
libc++abi.so.1 => /usr/local/lib/libc++abi.so.1 (0x00007fa4079fd000)
libc++.so.1 => /usr/local/lib/libc++.so.1 (0x00007fa407759000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fa40745c000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fa407246000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fa406e87000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fa406c69000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007fa406a61000)
/lib64/ld-linux-x86-64.so.2 (0x00007fa407c55000)

Can anyone give me a hint how to fix this?

Here is the backtrace:

[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Test cerr

Program received signal SIGABRT, Aborted.
0x00007ffff704e425 in raise () from /lib/x86_64-linux-gnu/libc.so.6
(gdb) backtrace
#0  0x00007ffff704e425 in raise () from /lib/x86_64-linux-gnu/libc.so.6
#1  0x00007ffff7051b8b in abort () from /lib/x86_64-linux-gnu/libc.so.6
#2  0x00007ffff792a437 in std::uncaught_exception() () from /usr/local/lib/libc++.so.1
#3  0x00007ffff79324e2 in std::__1::basic_ostream<char, std::__1::char_traits<char> >::sentry::~sentry() ()
   from /usr/local/lib/libc++.so.1
#4  0x000000000040118e in std::__1::operator<< <std::__1::char_traits<char> > (__os=..., __str=0x401784 "Test cerr \n")
    at /usr/local/include/c++/v1/ostream:990
#5  0x0000000000400d41 in main (argc=1, argv=0x7fffffffe728) at cerr_test.cpp:5
(gdb)

回答1:


It works finally by using libcxxrt instead libc++abi as suggested by @chico



来源:https://stackoverflow.com/questions/17590583/stdcerr-on-linux-with-clang-and-libc-causes-sigabrt

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