c++11并发编程问题记录(1):undefined reference to `pthread_create' collect2: error: ld returned 1 exit status

**写了一段简单的代码,如下:

#include <iostream>
#include <thread>
using namespace std;
void Hello()
{
  cout<<"Hello World"<<endl;
}
int main()
{
  thread my_thread(Hello);
  my_thread.join();
}

使用命令’g++ -std=c++11 HelloWorld.cpp’编译报错如下:**
在这里插入图片描述原因:链接失败
解决方法: g++ -std=c++11 HelloWorld.cpp -lpthread

在这里插入图片描述

人,总是要有一点精神的,不是吗

发布了32 篇原创文章 · 获赞 23 · 访问量 881

猜你喜欢

转载自blog.csdn.net/weixin_40179091/article/details/104967083