c++ - 无法解决 SIGABRT

c++ - Can't solve SIGABRT

我正在尝试 运行 一个简单的代码,它可以编译,但是当我尝试 运行 它时,我得到(核心转储)错误。于是用gdb查看错误是什么

代码:

#include <thread>
#include <iostream>
#include <stdio.h>


void gerar()
{
    printf("works\n");
}

int main()
{
    std::thread oi(gerar);
    printf("oi");

    return 0;
}

dgb 消息:

Traceback (most recent call last):
  File "/usr/share/gdb/auto-load/usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.19-gdb.py", line 63, in <module>
    from libstdcxx.v6.printers import register_libstdcxx_printers
ImportError: No module named 'libstdcxx'
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[New Thread 0x7ffff6fd6700 (LWP 4879)]
terminate called without an active exception

Program received signal SIGABRT, Aborted.
0x00007ffff7313cc9 in __GI_raise (sig=sig@entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:56
56  ../nptl/sysdeps/unix/sysv/linux/raise.c: No such file or directory.

g++ 行:

g++ -c teste.cpp -pthread -std=c++11  
g++ teste.o -o teste -pthread -std=c++11

线程的析构函数:

If *this has an associated thread (joinable() == true), std::terminate() is called.

这就是你的情况。

main 中调用 oi.join();