I'm having trouble getting multi-threading working. I'm using a very
simple example off the internet. It will compile but the thread
never runs. If I try to use "first" of "join()" I get an run time
error message about an "entry point" involving libstdc++-6.dll.
Here's the code:
#include <windows.h>
#include <iostream>
#include <thread>
using namespace std;
t erminate called after throwing an instance of 'in foo std::system_error
'
what(): Invalid argument
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
Process returned 255 (0xFF) execution time : 4.445 s
Press any key to continue.
I changed the line:
std::thread (foo);
to:
std::thread t1(foo);
It compiles but I get the runtime error message:
The procedure entry point
_ZNSt6thread15_M_start_threadESt10unique_ptrINS_6_StateESt14d
efault_deleteIS1_EEPFvvE could not be located in the dynamic link
library libstdc++-6.dll
I added -pthread but it still failed. Then I enabled -std=c++11 for
-g;-O0;-std=c++11;-Wall -pthread Same error.
Based on some of the replies here I tried a different compiler and
it worked. I removed -pthread and it still worked but if I removed
-std=c++11 the error was "no rule to make target".
So the build line that works is -g;-O0;-std=c++11;-Wall
The compiler that worked is x86_64-w64-mingw32-g++.exe that came
with Code::Blocks 16.01.
Should also have at least -Wextra -pedantic-errors compile options. It's a good idea to compile with as many warnings turned on as possible - warnings are your friend.
Try to use the latest std the compiler supports: at the moment c++14, but c++17 is due out soon. g++ 6.3.1 already supports some of c++17, as does clang++ 3.9
That's not including the extra options I mentioned.
Try to get a better IDE than Code Blocks: there is no version control, and it doesn't do background compilation. There are lots of IDE's: I like QtCreator or KDevelop; could try Eclipse. Try a few see what you like.