Unable to Build ITK 5.* version on gcc / mingw 10 * - Pthread linking error/ windows10

108 views Asked by At

I am trying to compile itk from source, its with version 5.3. On a windows 10 64 bit machine and with mingw-w64 version 10 installed i am using cmake(latest version) to build the itk source.

How ever during build i am getting a linker error of " multiple definitions found for most of the pthread functions" coming from another source file .

As i am directly building from source and not supposed change the source files any can tell me how to avoid that error ?

I have tried with -fcommon --allow-multiple-definition linker options without any help.

Later found out that -fno-common was introduced in latest gcc versions.

also is there any way to build ITK this version with any other compiler in windows 10 ?

I have tried with windows sdk latest but that does not give me the option to generate make files through cmake. And gives a strange error of Nmake file not found even though it is a default cmake generator of windows.

Please note : I am not interested in installing visual studio . thats why cant get hold of msvc compilers.

47%] Building CXX object Modules/Core/Common/src/CMakeFiles/ITKCommon.dir/__/itkBuildInformation.cxx.obj [ 47%] Linking CXX shared library ........\bin\libITKCommon-5.2.dll c:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: c:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/lib/../lib/libpthread.a(libwinpthread_la-cond.o):cond.c:(.text+0x1100): multiple definition of pthread_cond_timedwait'; ../../../../lib/libitkdouble-conversion-5.2.dll.a(d000091.o):(.text+0x0): first defined here c:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: c:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/lib/../lib/libpthread.a(libwinpthread_la-thread.o):thread.c:(.text+0x14a0): multiple definition of pthread_once'; ../../../../lib/libitkdouble-conversion-5.2.dll.a(d000136.o):(.text+0x0): first defined here c:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: c:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/lib/../lib/libpthread.a(libwinpthread_la-thread.o):thread.c:(.text+0x1ac0): multiple definition of pthread_self'; ../../../../lib/libitkdouble-conversion-5.2.dll.a(d000150.o):(.text+0x0): first defined here c:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: c:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/lib/../lib/libpthread.a(libwinpthread_la-mutex.o):mutex.c:(.text+0x80): multiple definition of pthread_mutex_lock'; ../../../../lib/libitkdouble-conversion-5.2.dll.a(d000121.o):(.text+0x0): first defined here c:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: c:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/lib/../lib/libpthread.a(libwinpthread_la-mutex.o):mutex.c:(.text+0x3a0): multiple definition of pthread_mutex_unlock'; ../../../../lib/libitkdouble-conversion-5.2.dll.a(d000124.o):(.text+0x0): first defined here c:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: c:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/lib/../lib/libpthread.a(libwinpthread_la-mutex.o):mutex.c:(.text+0x520): multiple definition of pthread_mutex_init'; ../../../../lib/libitkdouble-conversion-5.2.dll.a(d000120.o):(.text+0x0): first defined here c:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: c:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/lib/../lib/libpthread.a(libwinpthread_la-mutex.o):mutex.c:(.text+0x570): multiple definition of `pthread_mutex_destroy'; ../../../../lib/libitkdouble-conversion-5.2.dll.a(d000119.o):(.text+0x0): first defined here collect2.exe: error: ld returned 1 exit status mingw32-make[5]: *** [Modules\Core\Common\src\CMakeFiles\ITKCommon.dir\build.make:1772: bin/libITKCommon-5.2.dll] Error 1 mingw32-make[4]: *** [CMakeFiles\Makefile2:5302: Modules/Core/Common/src/CMakeFiles/ITKCommon.dir/all] Error 2 mingw32-make[3]: *** [Makefile:155: all] Error 2 mingw32-make[2]: *** [CMakeFiles\ITK.dir\build.make:85: ep/src/ITK-stamp/ITK-build] Error 2 mingw32-make[1]: *** [CMakeFiles\Makefile2:1082: CMakeFiles/ITK.dir/all] Error 2 mingw32-make: *** [Makefile:145: all] Error 2

1

There are 1 answers

3
Dženan On BEST ANSWER

MinGW is neither officially supported, nor tested, so it is not surprising that it doesn't work. Contributions to add support are welcome.

Microsoft offers just the command-line compiler, without needing Visual Studio. You might also have better luck with Clang for Windows than MinGW.