g++ tells you to include a library that is already included
There is no error related to the crooked name
The error itself-I'm trying to make a list of threads, but the 'thread' was not declared
Thread library enabled
The part of the code I'm trying to parallelize
int division = poolsize/threads;
thread threadList[threads]{};
for(int i = 0; i < threads-1; ++i){
thread threadList[i] (...);
}
thread threadList[threads-1] (...);
Compiling g++ - Wall-o name.exe code.cpp
Operating system-Windows 7 64bit
Checked if I can create threads at all
#include <thread>
void nothing(){}
int main(){
std::thread a(nothing);}
The compiler gives the error-std:: thread is not declared, add #include thread.
Downloaded gcc from the first site (https://programforyou.ru/poleznoe/kak-ustanovit-gcc-dlya-windows)(ftp://ftp.equation.com/gcc/gcc-9.2.0-64.exe)
The compiler doesn't swear at #include
-std=c++11 didn't change anything
In the thread file itself, everything is under #if defined(_GLIBCXX_HAS_GTHREADS), can this somehow affect it?
1 answers
This is the normal behavior of gcc. You must specify the appropriate flag to the linker.
There is a man on gcc - man_gcc
Here is an excerpt that you should be interested in -
-pthread Add support for multithreading using the POSIX threads library. This option sets flags for both the preprocessor and linker. It does not affect the thread safety of object code produced by the compiler or that of libraries supplied with it. These are HP-UX specific flags.
Collect everything with the flag -pthread
gcc -std=c++17 -pthread *бла бла бла*
Or
gcc -std=c++17 MyProgram.c -o MyProgram -lpthread
Specify the standard at least 11!
P.S. zainklyudit header and linkankut library-generally different things in principle)