0
votes

I am trying to learn C++, and I cant seem to get threading to work.

#include <iostream>  
#include <thread>  
using namespace std;  

void thing(){  
    cout << "1 is a thing" << endl;  
    int num;
    cin >> num;
}  

int main(){  
    cout << "is 1 a thing?" << endl;  
    thread neat1(thing);  
    return 0;
}  

identifier "thread" is undefined
Im on C++14

minGW info:
Using built-in specs. COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=c:/mingw/bin/../libexec/gcc/mingw32/8.2.0/lto-wrapper.exe
Target: mingw32
Configured with: ../src/gcc-8.2.0/configure --build=x86_64-pc-linux-gnu --host=mingw32 --target=mingw32 --prefix=/mingw --disable-win32-registry --with-arch=i586 --with-tune=generic --enable-languages=c,c++,objc,obj- c++,fortran,ada --with-pkgversion='MinGW.org GCC-8.2.0-3' --with-gmp=/mingw --with-mpfr=/mingw --with-mpc=/mingw --enable-static --enable-shared --enable-threads --with-dwarf2 --disable-sjlj-exceptions --enable-version- specific-runtime-libs --with-libiconv-prefix=/mingw --with-libintl- prefix=/mingw --enable-libstdcxx-debug --with-isl=/mingw --enable-libgomp --disable-libvtv --enable-nls --disable-build-format-warnings
Thread model: win32
gcc version 8.2.0 (MinGW.org GCC-8.2.0-3)

this is what happends if I compile via cmd

>g++ first.cpp -std=c++11  
first.cpp: In function 'int main()':  
first.cpp:13:5: error: 'thread' was not declared in this scope  
     thread neat1(thing);  
     ^~~~~~  
first.cpp:13:5: note: 'std::thread' is defined in header '<thread>'; did you   forget to '#include <thread>'?  
first.cpp:3:1:  
+#include <thread>  
 using namespace std;  
first.cpp:13:5:  
     thread neat1(thing);  
     ^~~~~~
1
Check if you're using at least C++11.João Paulo
1) main(){ should be int main(){ 2) Are you compiling with C++-11 enabled?Algirdas Preidžius
What is your compiler version and how do you compile (options used for compilation)?Yksisarvinen
Im using minGW and by options do you mean the .json's? (sorry as you can tell, I'm very new to alot of this)yes
What version? I don't think the 32 bit version supports threadNathanOliver

1 Answers

0
votes

My compiler turned out to be the issue, so I removed the old one and got a new MinGW compiler from https://sourceforge.net/projects/mingw-w64/files/ from the online installer. After setting that up threading worked.