# build VTK9.1.0 error use Mingw64 in win10

**URL:** https://discourse.vtk.org/t/build-vtk9-1-0-error-use-mingw64-in-win10/7076
**Category:** Support
**Created:** [November 5, 2021, 2:16am UTC](https://discourse.vtk.org/t/build-vtk9-1-0-error-use-mingw64-in-win10/7076 "2021-11-05T02:16:14Z")
**Posts on this page:** 14
**Page:** 1

<div class="post-metadata">

### Author: ![Lee1](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/l/f9ae1b/32.png) [@Lee1](https://discourse.vtk.org/u/Lee1)
#### Post date: [November 5, 2021, 2:16am UTC](https://discourse.vtk.org/t/build-vtk9-1-0-error-use-mingw64-in-win10/7076/1 "2021-11-05T02:16:14Z")

</div>

```auto
[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

```

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.vtk.org/user_avatar/discourse.vtk.org/mwestphal/32/19_2.png) [@mwestphal](https://discourse.vtk.org/u/mwestphal)
#### Post date: [November 5, 2021, 8:57am UTC](https://discourse.vtk.org/t/build-vtk9-1-0-error-use-mingw64-in-win10/7076/2 "2021-11-05T08:57:49Z")

</div>

AFAIK VTK is not tested with mingw

---

<div class="post-metadata">

### Author: ![Lee1](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/l/f9ae1b/32.png) [@Lee1](https://discourse.vtk.org/u/Lee1)
#### Post date: [November 5, 2021, 1:16pm UTC](https://discourse.vtk.org/t/build-vtk9-1-0-error-use-mingw64-in-win10/7076/3 "2021-11-05T13:16:40Z")

</div>

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

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.vtk.org/u/ben.boeckel)
#### Post date: [November 5, 2021, 2:37pm UTC](https://discourse.vtk.org/t/build-vtk9-1-0-error-use-mingw64-in-win10/7076/4 "2021-11-05T14:37:36Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Lee1](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/l/f9ae1b/32.png) [@Lee1](https://discourse.vtk.org/u/Lee1)
#### Post date: [November 5, 2021, 2:47pm UTC](https://discourse.vtk.org/t/build-vtk9-1-0-error-use-mingw64-in-win10/7076/5 "2021-11-05T14:47:22Z")

</div>

I find code in file vtkImageStencilIterator.h

```auto
#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

```auto
#define vtkImageStencilIterator_cxx

```

---

<div class="post-metadata">

### Author: ![jschueller](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jschueller/32/3398_2.png) [@jschueller](https://discourse.vtk.org/u/jschueller)
#### Post date: [November 5, 2021, 7:35pm UTC](https://discourse.vtk.org/t/build-vtk9-1-0-error-use-mingw64-in-win10/7076/6 "2021-11-05T19:35:50Z")

</div>

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

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [November 5, 2021, 8:11pm UTC](https://discourse.vtk.org/t/build-vtk9-1-0-error-use-mingw64-in-win10/7076/7 "2021-11-05T20:11:52Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![Lee1](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/l/f9ae1b/32.png) [@Lee1](https://discourse.vtk.org/u/Lee1)
#### Post date: [November 5, 2021, 11:24pm UTC](https://discourse.vtk.org/t/build-vtk9-1-0-error-use-mingw64-in-win10/7076/8 "2021-11-05T23:24:28Z")

</div>

I do nothing.

---

<div class="post-metadata">

### Author: ![Lee1](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/l/f9ae1b/32.png) [@Lee1](https://discourse.vtk.org/u/Lee1)
#### Post date: [November 5, 2021, 11:28pm UTC](https://discourse.vtk.org/t/build-vtk9-1-0-error-use-mingw64-in-win10/7076/9 "2021-11-05T23:28:56Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Lee1](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/l/f9ae1b/32.png) [@Lee1](https://discourse.vtk.org/u/Lee1)
#### Post date: [November 6, 2021, 12:33am UTC](https://discourse.vtk.org/t/build-vtk9-1-0-error-use-mingw64-in-win10/7076/10 "2021-11-06T00:33:16Z")

</div>

@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\>

---

<div class="post-metadata">

### Author: ![Lee1](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/l/f9ae1b/32.png) [@Lee1](https://discourse.vtk.org/u/Lee1)
#### Post date: [November 18, 2021, 2:23am UTC](https://discourse.vtk.org/t/build-vtk9-1-0-error-use-mingw64-in-win10/7076/11 "2021-11-18T02:23:47Z")

</div>

anyone can help ?

---

<div class="post-metadata">

### Author: ![jschueller](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jschueller/32/3398_2.png) [@jschueller](https://discourse.vtk.org/u/jschueller)
#### Post date: [November 18, 2021, 7:45am UTC](https://discourse.vtk.org/t/build-vtk9-1-0-error-use-mingw64-in-win10/7076/12 "2021-11-18T07:45:22Z")

</div>

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

---

<div class="post-metadata">

### Author: ![kchansen](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/k/4bbf92/32.png) [@kchansen](https://discourse.vtk.org/u/kchansen)
#### Post date: [November 15, 2023, 11:58pm UTC](https://discourse.vtk.org/t/build-vtk9-1-0-error-use-mingw64-in-win10/7076/13 "2023-11-15T23:58:54Z")

</div>

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.

```auto
=============================================================

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.
=============================================================

```

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.vtk.org/u/ben.boeckel)
#### Post date: [November 17, 2023, 4:18am UTC](https://discourse.vtk.org/t/build-vtk9-1-0-error-use-mingw64-in-win10/7076/14 "2023-11-17T04:18:17Z")

</div>

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).
