You're using pthreads, so use -pthreads
. -mthreads
is something else.
-mthreads on mingw 4.8.2 (on Fedora 20) now generating lihnking errors - should I use both -mthreads and -pthread?
Вопрос
I just upgraded to Fedora 20 for a cross-compile project. Fedora 20 is using MinGW 4.8.2-1.fc20. My code is mostly there, but I am getting many undefined references to pthread_mutex_init
and other pthread mutex functions on linking. I'm linking with the -mthreads
option because my code is multi-threaded and uses exceptions.
The linking errors go away if I say -pthread
. BUt that doesn't seem like the right think to do.
Here is a small test program:
#include <pthread.h>
int main(int argc,char **argv)
{
pthread_mutex_t M;
pthread_mutex_init(&M,0);
exit(0);
}
Sample compile:
$ x86_64-w64-mingw32-g++ -mthreads x.cpp
/tmp/ccqTnLlg.o:x.cpp:(.text+0x21): undefined reference to `pthread_mutex_init'
collect2: error: ld returned 1 exit status
$
I can make it go away with:
$ x86_64-w64-mingw32-g++ -mthreads x.cpp -pthread
$
But that seems wrong.
For those not familiar with what -mthread
is for, here is the section from the man page:
-mthreads
Support thread-safe exception handling on MinGW. Programs that rely on thread-safe exception handling must compile and link all code with the
-mthreads option. When compiling, -mthreads defines "-D_MT"; when linking, it links in a special thread helper library -lmingwthrd which
cleans up per-thread exception-handling data.
Any suggestions?
Решение
Не связан с StackOverflow