【发布时间】:2013-10-28 02:52:58
【问题描述】:
我有最简单的代码:
#include <iostream>
#include <thread>
void worker()
{
std::cout << "another thread";
}
int main()
{
std::thread t(worker);
std::cout << "main thread" << std::endl;
t.join();
return 0;
}
虽然我仍然无法用g++ 编译它来运行。
更多细节:
$ g++ --version
g++ (Ubuntu/Linaro 4.8.1-10ubuntu8) 4.8.1
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
编译命令:
$ g++ main.cpp -o main.out -pthread -std=c++11
跑步:
$ ./main.out
terminate called after throwing an instance of 'std::system_error'
what(): Enable multithreading to use std::thread: Operation not permitted
Aborted (core dumped)
现在我陷入了困境。建议在互联网上的每个相关线程中添加-pthread,而我已经拥有它。
我做错了什么?
PS:这是一个全新的 ubuntu 13.10 安装。仅安装了 g++ 包和诸如 chromium 之类的小东西
PPS:
$ ldd ./a.out
linux-vdso.so.1 => (0x00007fff29fc1000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007fb85397d000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fb853767000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fb85339e000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fb85309a000)
/lib64/ld-linux-x86-64.so.2 (0x00007fb853c96000)
PPPS:使用 clang++ (v3.2) 编译并运行良好
PPPPS:伙计们,这不是What is the correct link options to use std::thread in GCC under linux?的复制品
PPPPS:
$ dpkg --get-selections | grep 'libc.*dev'
libc-dev-bin install
libc6-dev:amd64 install
libclang-common-dev install
linux-libc-dev:amd64 install
【问题讨论】:
-
这是指向同一目录中
libpthread-2.17.so的符号链接。 -
是的,这是一个正确的链接。这是我的目录 lrwxrwxrwx。 1 根 18 Sep 12 20:52 libpthread.so.0 -> libpthread-2.16.so
-
@Jason Enochs:这对我有用——我同意,如果我不使用有缺陷的 gcc 版本
-
是的,你所有的库都比我的更新一点:gcc 版本 4.7.2 20121109 (Red Hat 4.7.2-8) (GCC)
-
@Jason Enochs:呵呵。对我自己来说,我已经对“这是一个错误”的答案感到满意,明天可能会尝试在较旧的 ubuntu 上运行它,只是为了完全确定