'Building jq on Win10 using mingw fails at link time due to redefinition of pthread_key_create / pthread_setspecific / pthread_getspecific
I apologize as I haven't dealt with C in a professional capacity in over 20 years, so maybe there's an obvious fix here.
When building within mingw64 I can get to the point where the linker is running for jq.exe, but the pthread specific code is giving me errors:
CCLD jq.exe
(and this is just one of three similar errors that follow:)
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.3.0/../../../../lib\libpthread.a(libwinpthread_la-thread.o):(.text+0x12e0): multiple definition of `pthread_key_create'; ./.libs/libjq.a(jv.o):C:\msys64\home\build\ws\jq\build\win64\tmp/../../../src/jv.c:338: first defined here
I have used pacman to install what I believed were the necessary libraries/tools, but is there something that will prevent the configure/make process from including the pthread library since it looks like the preprocessor is trying to avoid including <pthread.h> ? Is that even the correct approach for this problem?
My build steps:
- built the oniguruma library (v 5.9.6) and put that into jq/modules/oniguruma.
 - autoreconf -fi
 - ./configure
 - make distclean
 - scripts/crosscompile win64 --disable-shared --enable-static --enable-all-static --target=win64-x86_64 --host=x86_64-w64-mingw32 --with-oniguruma=/home/build/proto/win64/usr/local
 
At the end of the compilation step, the linker fails because the WIN32 threading code from jv.c is colliding with the definitions in the winpthread files that are being linked in.
THANKS!
Solution 1:[1]
I can build jq 1.6 just fine in MSYS2 shell, but I didn't need autoreconf or scripts/crosscompile at all.
Here's what I did (I already had onigurama 6.9.8 on my system):
# change the next line to point to the proper destination
INSTALLPREFIX=C:/TEMP/jq
./configure --prefix=$INSTALLPREFIX &&
 # fix building DLLs
 sed -i.bak -e "s/\(allow_undefined=\)yes/\1no/" libtool &&
 make install-strip &&
 echo SUCCESS
    					Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source | 
|---|---|
| Solution 1 | Brecht Sanders | 
