【发布时间】:2017-02-04 22:54:54
【问题描述】:
我在尝试从标准模板库编译具有多线程的程序时遇到了一些麻烦。 当我尝试编译以下程序时,它返回给我一个模糊的错误:
#include <iostream>
#include <thread>
void foo()
{
std::cout << "Thread 1\n";
}
int main(int argc, char** argv)
{
std::thread tr(foo);
std::cout << "Main thread\n";
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
谁能帮帮我?
【问题讨论】:
标签: c++ multithreading g++ std stdthread