c++使用thread类时编译出错,对‘pthread_create’未定义的引用
来源:互联网 发布:远程监控软件 编辑:程序博客网 时间:2024/05/29 19:02
例子1
#include <iostream>
#include <thread>
using namespce std;
void hello()
{
cout << "hello concurent world!";
}
int main (int argc, char * argv[])
{
thread t(hello);
t.join();
return 0;
}
这个小例子直接用make编译是无法通过的。会报错
/tmp/ccYB66pt.o:在函数‘std::thread::thread<void (&)()>(void (&)())’中:
1-1.cpp:(.text._ZNSt6threadC2IRFvvEJEEEOT_DpOT0_[_ZNSt6threadC5IRFvvEJEEEOT_DpOT0_]+0x21):对‘pthread_create’未定义的引用
collect2: 错误:ld 返回 1
<builtin>: recipe for target '1-1' failed
make: *** [1-1] Error 1
解决方法是在编译的时候加上-lpthread参数。这个类用到posix实现的线程了。
g++ -o test test.cpp -lpthread
./test
结果输出 hello concurent world!
0 0
- c++使用thread类时编译出错,对‘pthread_create’未定义的引用
- 对‘pthread_create’未定义的引用
- 对pthread_create未定义的引用
- 对‘pthread_create’未定义的引用
- 对‘pthread_create’未定义的引用
- 对‘pthread_create’未定义的引用
- 对pthread_create未定义的引用
- 对‘pthread_create’未定义的引用
- 编译Linux程序出现“对‘pthread_create’未定义的引用”
- Linux编译问题:对‘pthread_create’未定义的引用
- 对‘pthread_create’未定义的引用 对‘pthread_join’未定义的引用
- 对‘pthread_create’未定义的引用 对‘pthread_join’未定义的引用
- codeblocks 多线程编程时:对pthread_create未定义的引用
- 问题解决: 对‘pthread_create’未定义的引用
- pthread_create 未定义的引用
- pthread_create 未定义的引用
- 关于编译FreeModbus提示 对'pthread_create'未定义的引用 的解决
- 对‘pthread_create’未定义的引用 这个错误的解决方法
- 占位
- 占位
- 占位
- 占位
- HDU 2845 Beans(dp)
- c++使用thread类时编译出错,对‘pthread_create’未定义的引用
- 占位
- linux设备驱动程序之时钟管理
- 每次进步一点点——Spark 中的宽依赖和窄依赖
- 占位
- 占位
- 占位
- 占位
- 动态规划之背包问题(一)