Attempting to use threads in C++ for the first time. Here is my code:
#include <iostream>
#include <thread>
int main(){
std::thread th;
}
To compile, I am using:
g++ -g -Wall -std=c++11 -pthread threadtest.cpp
This gives the following error:
$ g++ -g -Wall -std=c++11 -pthread threadtest.cpp
threadtest.cpp: In function 'int main()':
threadtest.cpp:5:8: error: 'thread' is not a member of 'std'
5 | std::thread th;
| ^~~~~~
threadtest.cpp:3:1: note: 'std::thread' is defined in header '<thread>'; did you forget to
'#include <thread>'?
2 | #include <thread>
+++ |+#include <thread>
3 |
If I comment out the "std::thread th" line, the error message changes to:
$ g++ -g -Wall -std=c++11 -pthread threadtest.cpp
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: cannot find -lpthread
collect2.exe: error: ld returned 1 exit status
Operating system: Windows 10. Seems to get the same result whether I'm using the plane-old windows command line or if I do it in Cygwin. Anyone know what's wrong? Thanks in advance.