我尝试使用标准模板库进行多线程编译时遇到了一些问题。 当我尝试编译以下程序时,它会返回一个晦涩的错误:
#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