#include <iostream>
#include <thread>
using namespace std;
void func()
{
cout << "hello world";
}
int main()
{
thread t(func);
t.join();
return 0;
}
为什么要加上-pthread编译选项才能链接成功呢?
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
pthread是linux下的线程库,用了多线程就要链接这个库,这时候要在编译选项上增加-pthread或者-lpthread-pthread选项对 预处理器和链接器起作用而老式的
-lpthread只对链接器起作用推荐使用
-pthreadPOSIX线程(POSIX threads),简称Pthreads,是线程的POSIX标准。该标准定义了创建和操纵线程的一整套API。在类Unix操作系统(Unix、Linux、Mac OS X等)中,都使用Pthreads作为操作系统的线程。