VTK 9.1, MINGW64 and Windows 10

Dear VTK Users and Developers,

My apologies if this is not the right place to report this issue, I’d be happy to move the subject in another forum if needed.

I have spent now two days trying to compile VTK from source as I need to switch from GCC 8 to GCC 11.2, and I am getting all sorts of weird things going on.

I have downloaded the source from the VTK website (https://vtk.org/download/, VTK-9.1.0.tar.gz). I have CMake 3.17.3, Windows 10 and I use the MinGW64 distribution to compile the source (with GCC 11.2).

GCC 11.2 has been obtained from WinLibs MinGW (GitHub - brechtsanders/winlibs_mingw: winlibs standalone build of GCC compiler and MinGW-w64, filename “winlibs-x86_64-posix-seh-gcc-11.2.0-llvm-13.0.0-mingw-w64ucrt-9.0.0-r2.7z”) - and to me it looks like a standard MinGW64 distribution - but I’d love to be proven wrong of course.

I also need to compile with Python support and - although I am still on Python 2.7 for legacy reasons - this is not the problem here. I had compiled VTK 9.0.0 a few weeks ago with GCC 8 and I had no problems whatsoever. And the error I am getting does not seem to be related to wrapping Python or not.

It takes quite some time to rebuild VTK - I can’t really use the parallel builds as I am not sure whether the errors the compiler gives are going to be easy to spot, so I re-run (once again) a serial build. Please bear in mind that I deleted the cache in CMake, removed the build folder, cleaned everything multiple times and restarted the whole thing again and again.

Everything works fine until about 34% of the build, where I start getting a bunch of warnings related to libtiff:

C:\Users\USER\Downloads\VTK-9.1.0\ThirdParty\tiff\vtktiff\libtiff\vtk_tiff_mangle.h:5:28: warning: array 'vtktiff__TIFFBuiltinCODECS' assumed to have one element
    5 | #define _TIFFBuiltinCODECS vtktiff__TIFFBuiltinCODECS
      |                            ^~~~~~~~~~~~~~~~~~~~~~~~~~
C:\Users\USER\Downloads\VTK-9.1.0\ThirdParty\tiff\vtktiff\libtiff\tiffiop.h:434:32: note: in expansion of macro '_TIFFBuiltinCODECS'
  434 | vtktiff_EXPORT const TIFFCodec _TIFFBuiltinCODECS[];
      |                                ^~~~~~~~~~~~~~~~~~
In file included from C:\Users\J0514162\Downloads\VTK-9.1.0\ThirdParty\tiff\vtktiff\libtiff\tiff.h:28,
                 from C:\Users\J0514162\Downloads\VTK-9.1.0\ThirdParty\tiff\vtktiff\libtiff\tiffio.h:31,
                 from C:\Users\J0514162\Downloads\VTK-9.1.0\ThirdParty\tiff\vtktiff\libtiff\tiffiop.h:49,
                 from C:\Users\J0514162\Downloads\VTK-9.1.0\ThirdParty\tiff\vtktiff\libtiff\tif_zstd.c:25:
C:\Users\USER\Downloads\VTK-9.1.0\ThirdParty\tiff\vtktiff\libtiff\vtk_tiff_mangle.h:5:28: warning: array 'vtktiff__TIFFBuiltinCODECS' assumed to have one element

And so on, until the build breaks with the error I am attaching (summary: collect2.exe: error: ld returned 1 exit status).

I am by no means an expert in compiler flags or compilation stuff, on the contrary, so I am completely lost. Could someone please point me in a possible direction on how to investigate this issue - and potentially solve it?

I will appreciate any suggestion you may have, and I thank you very much in advance for your help.


Compiler Error (start and end only)

C:\Users\USER\Downloads\VTK-9.1.0\ThirdParty\tiff\vtktiff\libtiff\tiffiop.h:434:32: note: in expansion of macro '_TIFFBuiltinCODECS'
  434 | vtktiff_EXPORT const TIFFCodec _TIFFBuiltinCODECS[];
      |                                ^~~~~~~~~~~~~~~~~~
c:/users/USER/tools/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\tiff.dir/objects.a(tif_close.c.obj):tif_close.c:(.rdata+0x10): multiple definition of `vtktiff__TIFFBuiltinCODECS'; CMakeFiles\tiff.dir/objects.a(tif_aux.c.obj):tif_aux.c:(.rdata+0x270): first defined here
c:/users/USER/tools/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\tiff.dir/objects.a(tif_close.c.obj):tif_close.c:(.bss+0x0): multiple definition of `vtktiff__TIFFerrorHandlerExt'; CMakeFiles\tiff.dir/objects.a(tif_aux.c.obj):tif_aux.c:(.bss+0x0): first defined here

... many more similar lines ...

collect2.exe: error: ld returned 1 exit status
make[2]: *** [ThirdParty\tiff\vtktiff\libtiff\CMakeFiles\tiff.dir\build.make:768: bin/libvtktiff-9.1.dll] Error 1
make[1]: *** [CMakeFiles\Makefile2:11985: ThirdParty/tiff/vtktiff/libtiff/CMakeFiles/tiff.dir/all] Error 2
make: *** [makefile:152: all] Error 2

vtk9.1.0_error.txt (64.5 KB)

1 Like

I don’t want to speak too early (the build is still going on) but I got to 64% without errors this time. And apparently all of this is due to a change in behavior for GCC between version 9 and 10:



The problem is that VTK appears to have functions and globals defined (as opposed to declared ) in header files. Therefore, those functions are pulled into multiple c/cxx files when they are compiled. Then during the linking phase, the linker sees multiple definitions.

Adding “-fcommon” as a C/CXX flag in CMake seems to make it work… but I’ll confirm if the build ends successfuly.

1 Like

So what happened now? Did it work?
I use Qt’s Mingw64 to build VTK9.1

It did work, yes. Finally I have a fresh VTK 9.1 and I can switch all our applications to GCC 11. Long fight, but worth it :slight_smile:


We don’t do too much surgery on upstream code we import. I would report this to libtiff upstream to move the definitions out of headers. Once it’s fixed there, we can bring it into VTK as well.

I upgraded from gcc 8.3 (MSYS2/MinGW64), which compiled VTK 9.1 just fine, to 11.2 and I started to get those redefinition errors. I confirm that adding -fcommon to the compiler flags works. Did any of you start an issue in libtiff site already?

Hello friends, I am also updating VTK recently, but when I check the BUILD_SHARED_LIBS, mingw32-make process will generate a lot of inline function errors, which will eventually cause the compilation to fail. I wonder if you have encountered such a problem?


Did you try the -fcommon compiler flag? There was a change in GCC behavior meaning that fno-common is now the default.



Thanks, I’ll try

failed again…

What were the errors?

That’s a warning, not an error. I get lots of those when I link my programs against VTK. Although warnings signal potential problems, I think, in this case, you can safely ignore them as they are caused by double/multiple declarations of the same function: one with and other without the __declspec(dllimport) . Either this or you tweak VTK code to add __declspec(dllimport) to all declarations of the offending functions or make them different symbols by adding inline, for instance.

this is template

class VTKIMAGINGCORE_EXPORT vtkImageStencilIterator : public vtkImagePointDataIterator

and I’m not good at Template


A template, as the name implies, is a code for a class or a function with a few parts missing. These parts are automatically filled by the preprocessor to make complete C++ code. A template helps the programmer such that writing code is minimized. For example, suppose you need to implement array classes for scalar types in your program. In classic C++ you need to write (and maintain!) one class for each data type: myArrayOfInt, myArrayOfFloat, myArrayOfDouble, etc. With templates, you simply declare just once:

template <class AnyType>
class Array{
    AnyType sum( AnyType a, AnyType b ){
       return a + b;

The code above is ignored by the compiler. But, when you write elsewhere something like Array<int> array_of_integers;, the preprocessor takes the template above and writes something like this on the fly for the compiler to compile:

class ArrayOfInt{
    int sum( int a, int b ){
       return a + b;

This is called generic programming. With templates, you improve productivity and maximize code reuse. Does this make sense?



:sweat_smile: :joy: :joy: :joy: :joy:

What’s so funny?

1 Like

This is VTK source, I just wanna build VTK with Mingw64.

Ok. We can start by you telling us what is the error you’re getting.

1 config everything with CMAKE-gui, because I use Qt make UI,so I confige GCC ,

2 I do this when I built VTK 9.0.1, It’s ok.
3 now, I wann upgrade VTK9.1.0

4 then , build VTK ,

5 but failed. This part file no change from VTK 9.0.1 !!! really???

As I’m not very experienced with cmake, I was wondering how to do this. I believe I got it to work now, so I’m answering for future visitors who are wondering the same.

  • I believe the flags could be changed in the ccmake (Linux) or cmake-gui (Windows) command. That was not an option for me for reasons that are irrelevant here.

  • What I did was modify VTK-9.1.0\CMake\vtkCompilerPlatformFlags.cmake to contain


and VTK-9.1.0\ThirdParty\tiff\CMakeLists.txt to contain

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fcommon" )

This is probably overkill, but it worked.