【发布时间】:2017-08-09 22:50:09
【问题描述】:
我正在尝试在 CLion 中运行这个简单的线程 c++ 程序
#include <iostream>
#include <thread>
using namespace std;
//Start of the thread t1
void hello() {
cout << "Hello,concurrent world!" << endl; }
int main() {
thread t1(hello); // spawn new thread that calls hello()
cout << "Concurrency has started!" << endl;
t1.join();
cout << "Concurrency completed!";
return 0;
}
我的问题是对 pthread 的未定义引用存在错误,我不明白我做错了什么......请注意我在 CLion 上这样做。
【问题讨论】:
-
你需要链接
-lpthread。 -
@Sam ... 或者
-pthread更好。 -
使用跨平台风格会好很多,这里列出:stackoverflow.com/a/4774027/3315622