build VTK9.1.0 error use Mingw64 in win10

[ 94%] Linking CXX shared library ..\..\bin\libvtkImagingMorphological-9.1d.dll
CMakeFiles\ImagingMorphological.dir/objects.a(vtkImageConnectivityFilter.cxx.obj):D:/workspaces/VTK/VTK-9.1.0.rc4/Imaging/Morphological/vtkImageConnectivityFilter.cxx:705: undefined reference to `vtkImageStencilIterator<int>::vtkImageStencilIterator(vtkImageData*, vtkImageStencilData*, int const*, vtkAlgorithm*, int)'
CMakeFiles\ImagingMorphological.dir/objects.a(vtkImageConnectivityFilter.cxx.obj):D:/workspaces/VTK/VTK-9.1.0.rc4/Imaging/Morphological/vtkImageConnectivityFilter.cxx:705: undefined reference to `vtkImageStencilIterator<unsigned short>::vtkImageStencilIterator(vtkImageData*, vtkImageStencilData*, int const*, vtkAlgorithm*, int)'
CMakeFiles\ImagingMorphological.dir/objects.a(vtkImageConnectivityFilter.cxx.obj):D:/workspaces/VTK/VTK-9.1.0.rc4/Imaging/Morphological/vtkImageConnectivityFilter.cxx:1035: undefined reference to `vtkImageStencilIterator<short>::vtkImageStencilIterator(vtkImageData*, vtkImageStencilData*, int const*, vtkAlgorithm*, int)'
CMakeFiles\ImagingMorphological.dir/objects.a(vtkImageConnectivityFilter.cxx.obj):D:/workspaces/VTK/VTK-9.1.0.rc4/Imaging/Morphological/vtkImageConnectivityFilter.cxx:1035: undefined reference to `vtkImageStencilIterator<unsigned short>::vtkImageStencilIterator(vtkImageData*, vtkImageStencilData*, int const*, vtkAlgorithm*, int)'
CMakeFiles\ImagingMorphological.dir/objects.a(vtkImageConnectivityFilter.cxx.obj):D:/workspaces/VTK/VTK-9.1.0.rc4/Imaging/Morphological/vtkImageConnectivityFilter.cxx:523: undefined reference to `vtkImageStencilIterator<short>::vtkImageStencilIterator(vtkImageData*, vtkImageStencilData*, int const*, vtkAlgorithm*, int)'
CMakeFiles\ImagingMorphological.dir/objects.a(vtkImageConnectivityFilter.cxx.obj):D:/workspaces/VTK/VTK-9.1.0.rc4/Imaging/Morphological/vtkImageConnectivityFilter.cxx:523: undefined reference to `vtkImageStencilIterator<unsigned short>::vtkImageStencilIterator(vtkImageData*, vtkImageStencilData*, int const*, vtkAlgorithm*, int)'
CMakeFiles\ImagingMorphological.dir/objects.a(vtkImageConnectivityFilter.cxx.obj):D:/workspaces/VTK/VTK-9.1.0.rc4/Imaging/Morphological/vtkImageConnectivityFilter.cxx:1035: undefined reference to `vtkImageStencilIterator<int>::vtkImageStencilIterator(vtkImageData*, vtkImageStencilData*, int const*, vtkAlgorithm*, int)'
collect2.exe: error: ld returned 1 exit status
mingw32-make[2]: *** [Imaging\Morphological\CMakeFiles\ImagingMorphological.dir\build.make:256: bin/libvtkImagingMorphological-9.1d.dll] Error 1
mingw32-make[1]: *** [CMakeFiles\Makefile2:11523: Imaging/Morphological/CMakeFiles/ImagingMorphological.dir/all] Error 2
mingw32-make: *** [Makefile:129: all] Error 2

AFAIK VTK is not tested with mingw

BUT I’m able to build VTK 9.0.1 with Mingw64. :joy:

@jschueller Do you have any insights here? I suspect the template export stuff isn’t valid for MinGW.

I find code in file vtkImageStencilIterator.h

#ifndef vtkImageStencilIterator_cxx
#ifdef _MSC_VER
#pragma warning(push)
// The following is needed when the vtkImageStencilIterator template
// class is declared dllexport and is used within vtkImagingCore
#pragma warning(disable : 4910) // extern and dllexport incompatible
#endif
vtkExternTemplateMacro(extern template class VTKIMAGINGCORE_EXPORT vtkImageStencilIterator);
#ifdef _MSC_VER
#pragma warning(pop)
#endif
#endif

#endif

and found the macro in file vtkImageStencilIterator.cxx

#define vtkImageStencilIterator_cxx

I dont have any problems with 9.1.0 in release mode mode, maybe try that.

The vtkImageStencilIterator.h/.cxx code hasn’t been touched for 5 years, so it definitely shouldn’t be causing new problems in VTK 9.1. Are you sure that you haven’t changed something in your build configuration?

I do nothing.

@jschueller I will try that. and in debug mode, how handle “too many sections (78878)” ??

@jschueller
the result is same

D:/workspaces/VTK/VTK-9.1.0.rc4/Common/DataModel/vtkPolyData.h:891:22: warning: ‘unsigned char vtkPolyData::GetCellPoints(vtkIdType, vtkIdType&, const vtkIdType*&)’ redeclared without dllimport attribute after being referenced with dll linkage
inline unsigned char vtkPolyData::GetCellPoints(
^~~~~~~~~~~
[ 93%] Linking CXX shared library …\bin\libvtkInteractionImage-9.1.dll
[ 93%] Built target InteractionImage
[ 93%] Built target vtkInteractionImage-hierarchy
[ 93%] Built target ImagingStencil
[ 93%] Built target vtkImagingStencil-hierarchy
[ 94%] Built target ImagingStatistics
[ 94%] Built target vtkImagingStatistics-hierarchy
[ 94%] Linking CXX shared library …\bin\libvtkImagingMorphological-9.1.dll
CMakeFiles\ImagingMorphological.dir/objects.a(vtkImageConnectivityFilter.cxx.obj):vtkImageConnectivityFilter.cxx:(.text+0xce68): undefined reference to vtkImageStencilIterator<short>::vtkImageStencilIterator(vtkImageData*, vtkImageStencilData*, int const*, vtkAlgorithm*, int)' CMakeFiles\ImagingMorphological.dir/objects.a(vtkImageConnectivityFilter.cxx.obj):vtkImageConnectivityFilter.cxx:(.text+0xd116): undefined reference to vtkImageStencilIterator::vtkImageStencilIterator(vtkImageData*, vtkImageStencilData*, int const*, vtkAlgorithm*, int)’
collect2.exe: error: ld returned 1 exit status
mingw32-make[2]: *** [Imaging\Morphological\CMakeFiles\ImagingMorphological.dir\build.make:256: bin/libvtkImagingMorphological-9.1.dll] Error 1
mingw32-make[1]: *** [CMakeFiles\Makefile2:11523: Imaging/Morphological/CMakeFiles/ImagingMorphological.dir/all] Error 2
mingw32-make: *** [Makefile:129: all] Error 2

D:\workspaces\VTK\VTK-9.1.0.rc4MinGW\shared>

anyone can help ?

maybe try to disable that module, see if there is a cmake option name morphological something