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

Building VTK9.3.0 with Mingw64 in Windows 10. Same error.

Building with CMake & Ninja under msys2/mingw64. It appears to be the final link that fails.

BTW – I had to add the following to CMakeLists.txt:

Line 9: add_compile_options(-Os -O3 -fcommon)

The -Os and -O3 optimizations were added to work around the error of “file too big”.
The -fcommon was added to fix the multiple-defined errors during link due to the header files using old-style function definitions which is now deprecated without the -fcommon to fold identical definitions into a single definition.

Everything builds except for the final link, which fails with the same error of the original post regarding VTK9.1.0 using Mingw64 on Win10. I doubt I am the only person on the planet trying to build VTK for Windows 10 using msys2/Mingw.

I see the referenced cxx files and the header file which includes the iterator, but it appears that for some reason the template is not getting instantiated for this combination of parameters.

Ideas? Thanks in advance for any assistance.

=============================================================

vtkImageConnectivityFilter.cxx:481: undefined reference
to `vtkImageStencilIterator<unsigned short>::vtkImageStencilIterator(vtkImageData*, vtkImageStencilData*, int const*, vtkAlgorithm*, int)'
=============================================================
$ ninja
[1/1] Linking CXX shared library bin\libvtkImagingMorphological-9.3d.dll
FAILED: bin/libvtkImagingMorphological-9.3d.dll lib/libvtkImagingMorphological-9.3d.dll.a
cmd.exe /C "cd . && C:\msys64\ucrt64\bin\c++.exe -Os -O3  -mwin32 -mthreads -g  -mthreads -shared -o bin\libvtkImagingMorphologic
al-9.3d.dll -Wl,--out-implib,lib\libvtkImagingMorphological-9.3d.dll.a -Wl,--major-image-version,9,--minor-image-version,3 Imagin
g/Morphological/CMakeFiles/ImagingMorphological.dir/vtkImageConnectivityFilter.cxx.obj Imaging/Morphological/CMakeFiles/ImagingMo
rphological.dir/vtkImageConnector.cxx.obj Imaging/Morphological/CMakeFiles/ImagingMorphological.dir/vtkImageContinuousDilate3D.cx
x.obj Imaging/Morphological/CMakeFiles/ImagingMorphological.dir/vtkImageContinuousErode3D.cxx.obj Imaging/Morphological/CMakeFile
s/ImagingMorphological.dir/vtkImageDilateErode3D.cxx.obj Imaging/Morphological/CMakeFiles/ImagingMorphological.dir/vtkImageIsland
Removal2D.cxx.obj Imaging/Morphological/CMakeFiles/ImagingMorphological.dir/vtkImageNonMaximumSuppression.cxx.obj Imaging/Morphol
ogical/CMakeFiles/ImagingMorphological.dir/vtkImageOpenClose3D.cxx.obj Imaging/Morphological/CMakeFiles/ImagingMorphological.dir/
vtkImageSeedConnectivity.cxx.obj Imaging/Morphological/CMakeFiles/ImagingMorphological.dir/vtkImageSkeleton2D.cxx.obj Imaging/Mor
phological/CMakeFiles/ImagingMorphological.dir/vtkImageThresholdConnectivity.cxx.obj  -lgdi32  lib/libvtkImagingGeneral-9.3d.dll.
a  lib/libvtkImagingSources-9.3d.dll.a  lib/libvtkImagingCore-9.3d.dll.a  lib/libvtkCommonExecutionModel-9.3d.dll.a  lib/libvtkCo
mmonDataModel-9.3d.dll.a  lib/libvtkCommonTransforms-9.3d.dll.a  lib/libvtkCommonMath-9.3d.dll.a  lib/libvtkCommonCore-9.3d.dll.a
  lib/libvtksys-9.3d.dll.a  -lws2_32  -lpsapi  lib/libvtkkissfft-9.3d.dll.a  -lgdi32  -lkernel32 -luser32 -lgdi32 -lwinspool -lsh
ell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 && cd ."
C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: Imaging/Morphological/CMakeF
iles/ImagingMorphological.dir/vtkImageConnectivityFilter.cxx.obj: in function `ExecuteInput<short int>':
C:/Projects/VTK-9.3.0/Imaging/Morphological/vtkImageConnectivityFilter.cxx:481: undefined reference to `vtkImageStencilIterator<s
hort>::vtkImageStencilIterator(vtkImageData*, vtkImageStencilData*, int const*, vtkAlgorithm*, int)'
C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: Imaging/Morphological/CMakeF
iles/ImagingMorphological.dir/vtkImageConnectivityFilter.cxx.obj: in function `ExecuteInput<short unsigned int>':
C:/Projects/VTK-9.3.0/Imaging/Morphological/vtkImageConnectivityFilter.cxx:481: undefined reference to `vtkImageStencilIterator<u
nsigned short>::vtkImageStencilIterator(vtkImageData*, vtkImageStencilData*, int const*, vtkAlgorithm*, int)'
collect2.exe: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
=============================================================

I suspect we need to at least smoke test MinGW builds for release cycles. There are a number of issues cropping up recently (all template-related AFAIK).

1 Like