首页 > gcc使用std::thread运行出现 `std::thread: Operation not permitted`

gcc使用std::thread运行出现 `std::thread: Operation not permitted`

使用std::thread,编译gcc不使用静态编译选项-static编译运行都正常,但是使用-static静态编译没有问题,但是运行出现如下错误:

terminate called after throwing an instance of 'std::system_error'
  what():  Enable multithreading to use std::thread: Operation not permitted

coredump 信息:

Program terminated with signal SIGABRT, Aborted.
#0  0x000000000043f5f7 in raise ()
(gdb) bt
#0  0x000000000043f5f7 in raise ()
#1  0x000000000040630a in abort ()
#2  0x00000000004d5465 in __gnu_cxx::__verbose_terminate_handler() ()
#3  0x00000000004957e6 in __cxxabiv1::__terminate(void (*)()) ()
#4  0x0000000000495831 in std::terminate() ()
#5  0x00000000004941f8 in __cxa_throw ()
#6  0x00000000004d4c5d in std::thread::_M_start_thread(std::shared_ptr<std::thread::_Impl_base>) ()
#7  0x0000000000488941 in std::thread::thread<void (client::Client::*)(int), client::Client*, int&>(void (client::Client::*&&)(int), client::Client*&&, int&) (this=0x1b73bf0, 
    __f=<unknown type in /home/cnsworder/workspace/vscd/01Develop/cmake/build/bin/file_client, CU 0x91ef, DIE 0x1a07d>)
    at /usr/include/c++/4.9.1/thread:135
#8  0x00000000004853d6 in client::Client::initHttpHost (this=0x7fff97873dc0, ip=0x1b4bcb8 "127.0.0.1", port=8090)
    at /home/cnsworder/workspace/vscd/01Develop/libclient/Client.cpp:127
#9  0x00000000004847ae in main (argc=3, argv=0x7fff97873ff8)
    at /home/cnsworder/workspace/vscd/01Develop/file_client/main.cpp:123

根据stackoverflow上的方案添加: -Wl,--no-as-needed -pthread后仍旧出现以上的运行错误.

强制直接添加libpthread.a后编译时出现找不到__syscall_error符号的错误,添加libc.a后编译通过,仍旧出现上述错误.

注意:错误只在静态编译时出现

【热门文章】
【热门文章】