来自 c++11 的 std::thread 的问题
Issue with std::thread from c++11
我在尝试从标准模板库中编译具有多线程的程序时遇到了一些麻烦。当我尝试编译以下程序时,它会返回一个模糊的错误:
#include <iostream>
#include <thread>
void foo()
{
std::cout << "Thread 1n";
}
int main(int argc, char** argv)
{
std::thread tr(foo);
std::cout << "Main threadn";
tr.join();
return 0;
}
我不明白错误:
/tmp/ccE8EtL1.o : In the function « std::thread::thread<void (&)()>(void (&)()) » :
file.cpp:(.text._ZNSt6threadC2IRFvvEJEEEOT_DpOT0_[_ZNSt6threadC5IRFvvEJEEEOT_DpOT0_]+0x21) : undefined reference to « pthread_create »
collect2: error : ld has return 1 execution status code
我用:
g++ -std=c++14 file.cpp -o test -Wall
谁能帮我?
将-pthread
传递给编译器。这个标志结合了编译和链接 pthread 库所必需的东西(-lpthread
并不总是足够的(。看到这个问题。
相关文章:
- 警告处理为错误这里有什么问题
- 最小硬币更换问题(自上而下方法)
- 为"adjacent"变量赋值时出现问题
- 我的神经网络不起作用 [XOR 问题]
- 在Ubuntu 16.04上安装Cilk时出现问题
- C++我的数学有什么问题,为什么我的代码不能正确循环
- 编译包含字符串的代码时遇到问题
- Project Euler问题4的错误解决方案
- 问题:什么是QAbstractItemView::NoEditTriggers的反面
- 在编译C++代码(具有dlib和opencv)到WASM时面临问题
- 在进程中对同一管道进行读取和写入时C++管道出现问题
- 静态数据成员的问题-修复链接错误会导致编译器错误
- C++ 雷神库 - 使用资源加载器类时出现问题(不命名类型)
- 一个关于在C++中重载布尔运算符的问题
- 首要问题的答案让值班员搞错了
- 子类化 std::thread:构造器中可变参数模板函数的问题
- 关于std::thread类的问题
- 来自 c++11 的 std::thread 的问题
- 将 boost/thread headers 与 clang++ (Windows) 一起使用时出现问题
- Printf调用与std::thread混淆,但std::cout没有问题