GNOME Bugzilla – Bug 593857
Build fails on MinGW 4.4 due to faulty thread lib detection
Last modified: 2009-09-10 20:46:26 UTC
Compiler: MinGW GCC 4.4 (full install) libxml2 configuration: default Building libxml2 fails because the library is trying to use both pthreads and Win32 threads at the same time. A look at the code in threads.c shows that it assumes that the defines HAVE_PTHREAD_H and HAVE_WIN32_THREADS are mutually exclusive. However, with the latest (June 2009) MinGW build, which includes pthread support, this assumption no longer holds and several errors turn up. Secondly, the code assumes that pthread_t is an integer, so at several points in threads.c it does operations on pthread_t that are only valid on integers. However, in MinGW 4.4's pthread library, MinGW is defined as a struct type, as follows (taken from MinGW's pthread.h): typedef struct { void * p; /* Pointer to actual object */ unsigned int x; /* Extra information - reuse count etc */ } ptw32_handle_t; typedef ptw32_handle_t pthread_t; I don't know whether POSIX mandates that pthread_t must be an int, or that MinGW is allowed to use a struct instead. Either MinGW or libxml2's code is at fault here, I don't know. Here is a listing of the compiler errors I get: threads.c: In function 'xmlRMutexUnlock': threads.c:415: error: incompatible types when assigning to type 'pthread_t' from type 'int' threads.c: In function '__xmlGlobalInitMutexDestroy': threads.c:534: warning: passing argument 1 of 'DeleteCriticalSection' from incompatible pointer type d:\devel\tools\mingw\bin\../lib/gcc/mingw32/4.4.0/../../../../include/winbase.h: 1289: note: expected 'PCRITICAL_SECTION' but argument is of type 'pthread_mutex_t' threads.c: In function 'xmlGetThreadId': threads.c:770: error: aggregate value used where an integer was expected threads.c: In function 'xmlIsMainThread': threads.c:806: error: invalid operands to binary == (have 'pthread_t' and 'pthread_t') threads.c: In function 'xmlCleanupThreads': threads.c:903: warning: comparison between pointer and integer threads.c:917: warning: passing argument 1 of 'TlsFree' makes integer from pointer without a cast d:\devel\tools\mingw\bin\../lib/gcc/mingw32/4.4.0/../../../../include/winbase.h: 1994: note: expected 'DWORD' but argument is of type 'pthread_key_t' threads.c: At top level: threads.c:991: warning: no previous prototype for 'DllMain' threads.c: In function 'DllMain': threads.c:996: warning: comparison between pointer and integer threads.c:1000: warning: passing argument 1 of 'TlsGetValue' makes integer from pointer without a cast d:\devel\tools\mingw\bin\../lib/gcc/mingw32/4.4.0/../../../../include/winbase.h: 1995: note: expected 'DWORD' but argument is of type 'pthread_key_t' threads.c:1004: warning: passing argument 1 of 'TlsSetValue' makes integer from pointer without a cast d:\devel\tools\mingw\bin\../lib/gcc/mingw32/4.4.0/../../../../include/winbase.h: 1996: note: expected 'DWORD' but argument is of type 'pthread_key_t' threads.c:991: warning: unused parameter 'hinstDLL' threads.c:991: warning: unused parameter 'lpvReserved'
I have tried to cope with this but no garantee. IMHO you should just use thread native support i.e. undefine HAVE_PTHREAD_H when building with that compiler. Daniel
Building default config still fails, but no longer in thread.c. Build succeeds using --with-threads=native. Since it is preferable to build with native thread support on Win32, it's probably best to make this the default build mode on MinGW.