It seems that you are trying to use C++11 threads. If it is true, then
- correct
#include <thread>
and#include <iostream>
, i.e. do not use"
in these lines and add#
in front of them. - compile with
g++ -std=c++11 q.cpp -lpthread
(dependency order matters for newer g++)
Hint: when you are using threads in a static linked library and use this library in an executable, then you have to add the flag -pthread
to the link command for the executable. Example:
g++ Obj1.o Obj2.o MyStaticLib.a -o MyExecutable -pthread