久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

在 linux 下的 GCC 中使用 std::thread 的正確鏈接選項

What are the correct link options to use std::thread in GCC under linux?(在 linux 下的 GCC 中使用 std::thread 的正確鏈接選項是什么?)
本文介紹了在 linux 下的 GCC 中使用 std::thread 的正確鏈接選項是什么?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在嘗試將 std::thread 與 G++ 一起使用.這是我的測試代碼

Hi I am trying to use std::thread with G++. Here is my test code

#include <thread>
#include <iostream>

int main(int, char **){
    std::thread tt([](){ std::cout<<"Thread!"<<std::endl; });
    tt.join();
}

它可以編譯,但是當我嘗試運行它時,結果是:

It compiles, but when I try to run it the result is:

terminate called after throwing an instance of 'std::system_error'
  what():  Operation not permitted 
Aborted

我的編譯器版本:

$ g++ --version
g++ (Ubuntu/Linaro 4.6.1-9ubuntu3) 4.6.1
Copyright (C) 2011 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.

我的測試代碼有什么問題?

What is wrong with my test code?

更新:我使用以下命令行來編譯和運行我的代碼.

UPDATE: I use the following command line to compile and run my code.

$ g++ -std=c++0x test.cpp
$ ./a.out

我試過了

$ g++ -std=c++0x -lpthread test.cpp
$ ./a.out

還是一樣.

推薦答案

我覺得在Linux上pthread是用來實現std::thread的,所以需要指定-pthread代碼>編譯器選項.

I think on Linux pthread is used to implement std::thread so you need to specify the -pthread compiler option.

因為這是一個鏈接選項,所以這個編譯器選項需要在源文件之后:

As this is a linking option, this compiler option need to be AFTER the source files:

$ g++ -std=c++0x test.cpp -pthread

這篇關于在 linux 下的 GCC 中使用 std::thread 的正確鏈接選項是什么?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

What is the fastest way to transpose a matrix in C++?(在 C++ 中轉置矩陣的最快方法是什么?)
Sorting zipped (locked) containers in C++ using boost or the STL(使用 boost 或 STL 在 C++ 中對壓縮(鎖定)容器進行排序)
Rotating a point about another point (2D)(圍繞另一個點旋轉一個點 (2D))
Image Processing: Algorithm Improvement for #39;Coca-Cola Can#39; Recognition(圖像處理:Coca-Cola Can 識別的算法改進)
How do I construct an ISO 8601 datetime in C++?(如何在 C++ 中構建 ISO 8601 日期時間?)
Sort list using STL sort function(使用 STL 排序功能對列表進行排序)
主站蜘蛛池模板: 99国产精品久久久 | 欧美一区二区在线播放 | 精品视频成人 | 天天干视频网 | 91精品久久久久久久久中文字幕 | 欧美日韩在线免费 | 国产精品日韩欧美一区二区三区 | 日本中文字幕日韩精品免费 | 久久国产精品一区二区 | 337p日韩| 久久这里只有精品首页 | 99久久精品国产毛片 | 国产精品不卡 | 毛片a区 | 三级成人在线 | 欧美一级电影免费观看 | 久久视频一区 | 久久精品免费 | 亚洲高清网 | 欧美一区成人 | 亚洲第一视频网 | 久久综合九九 | 欧美一区免费 | 国产精品亚洲成在人线 | 日本久久黄色 | 日韩精品网站 | 色综合九九| 国产精品一区二 | 精品一区二区三区四区五区 | 在线免费av观看 | 奇米四色在线观看 | 国产日产精品一区二区三区四区 | 91在线成人| 日本三级全黄三级三级三级口周 | 久久一视频| 免费在线性爱视频 | 男女污污动态图 | 久久免费看 | 欧美中文字幕一区 | 激情六月丁香婷婷 | 欧美v日韩v |