Using pthread in c++(在 C++ 中使用 pthread)
问题描述
我在 *.cc
文件中使用 pthread.h
.当我尝试使用 pthread_exit(0);
或 pthread_join(mythrds[yy],NULL);
它说:
I am using pthread.h
in a *.cc
file. when I try to use pthread_exit(0);
or pthread_join(mythrds[yy],NULL);
it says:
.cc:(.text+0x3e): undefined reference to `pthread_exit'
当使用 gcc 在 *.c
文件中编译非常相似的代码时,它可以完美运行.如何在 c++ 中使用 pthread ..(我还添加了 -lpthread)
when complied very similar code in a *.c
file with gcc it work perfect. How Can I use pthread's in c++.. (I also added -lpthread)
..
void *myThreads ( void *ptr )
{
...
pthread_exit(0);
}
..
标志:
g++ -lpthread -Wall -static -W -O9 -funroll-all-loops -finline -ffast-math
推荐答案
您可以尝试使用 g++ 的 -pthread 选项.
You might try using the -pthread option to g++.
-pthread
Adds support for multithreading with the pthreads library. This
option sets flags for both the preprocessor and linker.
这篇关于在 C++ 中使用 pthread的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 C++ 中使用 pthread


基础教程推荐
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
- 这个宏可以转换成函数吗? 2022-01-01
- 我有静态或动态 boost 库吗? 2021-01-01
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
- 常量变量在标题中不起作用 2021-01-01
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01