Building VTK git 5a0129e461 with MingW64 9.5.0 GCC

Greetings all.

I have read in quite a few places that VTK has troubles under MingW and MSYS and have attempted as many workarounds as I can (eg CMAKE_CXX_FLAGS of -Wa,-mbig-obj for File too big errors and -O1 optimization with release build to work around some undefined reference errors). However, there is one undefined reference error I can’t seem to get past:

FAILED: bin/libvtkCommonDataModel-9.4.dll lib/libvtkCommonDataModel-9.4.dll.a
C:\windows\system32\cmd.exe /C "cd . && C:\gcc-9.5.0\mingw64\bin\c++.exe -mwin32 -mthreads -O3 -DNDEBUG  -mthreads -shared -o bin\libvtkCommonDataModel-9.4.dll -Wl,--out-implib,lib\libvtkCommonDataModel-9.4.dll.a -Wl,--major-image-version,9,--minor-image-version,4 @CMakeFiles\CommonDataModel.rsp && cd ."
c:/gcc-9.5.0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.5.0/../../../../x86_64-w64-mingw32/bin/ld.exe: Common/DataModel/CMakeFiles/CommonDataModel.dir/vtkBoundingBox.cxx.obj:vtkBoundingBox:(.text+0xa85b): undefined reference to vtkImplicitArray<vtkStructuredPointBackend<double> >::GetTypedTuple(long long, double*) const'
c:/gcc-9.5.0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.5.0/../../../../x86_64-w64-mingw32/bin/ld.exe: Common/DataModel/CMakeFiles/CommonDataModel.dir/vtkBoundingBox.cxx.obj:vtkBoundingBox:(.text+0xbd0b): undefined reference to vtkImplicitArray<vtkStructuredPointBackend<double> >::GetTypedTuple(long long, double*) const'
c:/gcc-9.5.0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.5.0/../../../../x86_64-w64-mingw32/bin/ld.exe: Common/DataModel/CMakeFiles/CommonDataModel.dir/vtkBoundingBox.cxx.obj:vtkBoundingBox:(.text+0xd1bb): undefined reference to vtkImplicitArray<vtkStructuredPointBackend<double> >::GetTypedTuple(long long, double*) const'
collect2.exe: error: ld returned 1 exit status

Cmake config and gen logs. Full make log. Full cmake_install.cmake file here.
Build setup:
winlibs_mingw’s GCC 9.5.0 + MinGW-w64 10.0.0 MSVCRT (release 1)
Chocolatey’s GNU make 4.4.1
Windows cmake 3.31.3
VTK cloned from kitware’s gitlab at commit hash 5a0129e46105c83d7c33bb65a3daa6506bb2cf59 (2 commits behind master as of this post).

For debugging purposes, make has been run with VERBOSE=1 and the CMAKE_VERBOSE_MAKEFILE has been set to ON in the cmake config.

The vtkImplicitArray was added in VTK 9.3. These “undefined reference” errors occur because MinGW does explicit template instantiations differently from MSVC or gcc/linux. I’m fairly sure that these templates can be made to work with MinGW, but I don’t know exactly what changes are needed.

Thank you! That is a very straightforward answer. As it was more of an experiment than a necessity, I will look into building VTK 9.2.