Problem with std :: thread from C ++ 11

I have some problems trying to compile a multi-threaded program from the standard template library. It returns me an obscure error when I try to compile the following program:

#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; } 

I do not understand the error:

 /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 

I will compile it with

g ++ -std = C ++ 14 file.cpp -o test -Wall

Can anybody help me?

+5
source share

Source: https://habr.com/ru/post/1263825/


All Articles