I am trying to compile the following program with mingw:
#include <pthread.h>
#include <errno.h>
#include <unistd.h>
#include <iostream>
#include <cstdio>
void *hello(void *id) {
int nid = *static_cast<int*>(id);
std::printf("Hello from thread %d\n", nid);
return 0;
}
int main(int argc, char **argv) {
pthread_t ids[2];
int *params[2];
for (int i = 0; i < 2; ++i) {
params[i] = new int;
*params[i] = i;
pthread_create(&ids[i], 0, hello, params[i]);
}
for (int i = 0; i < 2; ++i)
pthread_join(ids[i], 0);
for (int i = 0; i < 2; ++i)
delete params[i];
return 0;
}
using this command:
g++ -lpthread -ohello.exe hello.cc
And I get the following message:
C:\Users\XXXXXX~1\AppData\Local\Temp\cczPlv0w.o:hello.cc:(.text+0xad): undefined
reference to `_imp__pthread_create'
C:\Users\XXXXXX~1\AppData\Local\Temp\cczPlv0w.o:hello.cc:(.text+0xe9): undefined
reference to `_imp__pthread_join'
collect2: ld returned 1 exit status
But with an older version of MingGW I had no problems running pthreads programs. (This is just the simple of all the programs that failed, but basically everything that uses pthreads ends up with the same error, C and C++)