linux++编译线程,用G ++编译多线程代码
我有史以來最簡單的代碼:
#include
#include
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:伙計們,這不是Linux下在GCC中使用std :: thread的正確鏈接選項是什么的重復項?
PPPPPS:
$ dpkg --get-selections | grep 'libc.*dev'
libc-dev-bin? ? ? ? ? ? ? ? ? ? install
libc6-dev:amd64? ? ? ? ? ? ? ? ?install
libclang-common-dev? ? ? ? ? ? ?install
linux-libc-dev:amd64? ? ? ? ? ? ? ? install
總結
以上是生活随笔為你收集整理的linux++编译线程,用G ++编译多线程代码的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: linux 引导程序修复工具,技术|Li
- 下一篇: linux ssl 证书服务器,Linu