# VTK 9.1, MINGW64 and Windows 10

**URL:** https://discourse.vtk.org/t/vtk-9-1-mingw64-and-windows-10/7116
**Category:** Support
**Created:** [November 9, 2021, 7:53am UTC](https://discourse.vtk.org/t/vtk-9-1-mingw64-and-windows-10/7116 "2021-11-09T07:53:19Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![Andrea\_Gavana](https://discourse.vtk.org/user_avatar/discourse.vtk.org/andrea_gavana/32/1854_2.png) [@Andrea\_Gavana](https://discourse.vtk.org/u/Andrea_Gavana)
#### Post date: [November 9, 2021, 7:53am UTC](https://discourse.vtk.org/t/vtk-9-1-mingw64-and-windows-10/7116/1 "2021-11-09T07:53:19Z")

</div>

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/](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](https://github.com/brechtsanders/winlibs_mingw), 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:

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

Andrea.

**Compiler Error (start and end only)**

```auto
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](https://discourse.vtk.org/uploads/short-url/eDv41jKcQxJo4XVAx2xZdiON5BV.txt) (64.5 KB)

---

<div class="post-metadata">

### Author: ![Andrea\_Gavana](https://discourse.vtk.org/user_avatar/discourse.vtk.org/andrea_gavana/32/1854_2.png) [@Andrea\_Gavana](https://discourse.vtk.org/u/Andrea_Gavana)
#### Post date: [November 9, 2021, 1:46pm UTC](https://discourse.vtk.org/t/vtk-9-1-mingw64-and-windows-10/7116/3 "2021-11-09T13:46:18Z")

</div>

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:

[https://wiki.gentoo.org/wiki/Project:Toolchain/Gcc\_10\_porting\_notes/fno\_common](https://wiki.gentoo.org/wiki/Project:Toolchain/Gcc_10_porting_notes/fno_common)

Details:

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.

---

<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 10, 2021, 5:09am UTC](https://discourse.vtk.org/t/vtk-9-1-mingw64-and-windows-10/7116/4 "2021-11-10T05:09:03Z")

</div>

> [@Andrea\_Gavana](#):
>
> 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%

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

---

<div class="post-metadata">

### Author: ![Andrea\_Gavana](https://discourse.vtk.org/user_avatar/discourse.vtk.org/andrea_gavana/32/1854_2.png) [@Andrea\_Gavana](https://discourse.vtk.org/u/Andrea_Gavana)
#### Post date: [November 10, 2021, 5:52am UTC](https://discourse.vtk.org/t/vtk-9-1-mingw64-and-windows-10/7116/5 "2021-11-10T05:52:21Z")

</div>

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 🙂

Andrea

---

<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 15, 2021, 8:47pm UTC](https://discourse.vtk.org/t/vtk-9-1-mingw64-and-windows-10/7116/6 "2021-11-15T20:47:10Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [March 1, 2022, 9:20pm UTC](https://discourse.vtk.org/t/vtk-9-1-mingw64-and-windows-10/7116/7 "2022-03-01T21:20:03Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![S-Explorer](https://discourse.vtk.org/user_avatar/discourse.vtk.org/s-explorer/32/4783_2.png) [@S-Explorer](https://discourse.vtk.org/u/S-Explorer)
#### Post date: [March 4, 2022, 1:32am UTC](https://discourse.vtk.org/t/vtk-9-1-mingw64-and-windows-10/7116/8 "2022-03-04T01:32:58Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [March 4, 2022, 12:24pm UTC](https://discourse.vtk.org/t/vtk-9-1-mingw64-and-windows-10/7116/9 "2022-03-04T12:24:17Z")

</div>

Hello,

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

regards,

Paulo

---

<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: [April 11, 2022, 12:25am UTC](https://discourse.vtk.org/t/vtk-9-1-mingw64-and-windows-10/7116/10 "2022-04-11T00:25:36Z")

</div>

Thanks， I’ll try

failed again…

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [April 11, 2022, 1:44pm UTC](https://discourse.vtk.org/t/vtk-9-1-mingw64-and-windows-10/7116/11 "2022-04-11T13:44:14Z")

</div>

What were the errors?

---

<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: [April 11, 2022, 11:43pm UTC](https://discourse.vtk.org/t/vtk-9-1-mingw64-and-windows-10/7116/12 "2022-04-11T23:43:06Z")

</div>

> [@build VTK9.1.0 error use Mingw64 in win10](https://discourse.vtk.org/t/build-vtk9-1-0-error-use-mingw64-in-win10/7076/10):
>
> @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 …

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [April 12, 2022, 1:51pm UTC](https://discourse.vtk.org/t/vtk-9-1-mingw64-and-windows-10/7116/13 "2022-04-12T13:51:09Z")

</div>

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.

---

<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: [April 13, 2022, 6:39am UTC](https://discourse.vtk.org/t/vtk-9-1-mingw64-and-windows-10/7116/14 "2022-04-13T06:39:37Z")

</div>

this is template

“template   
class VTKIMAGINGCORE\_EXPORT vtkImageStencilIterator : public vtkImagePointDataIterator  
{  
public:  
…”

 ![image](https://discourse.vtk.org/uploads/default/original/2X/f/fe24a8e10285ac85999bf6c58d0a47f83ad897dc.png)

and I’m not good at Template

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [April 13, 2022, 11:40am UTC](https://discourse.vtk.org/t/vtk-9-1-mingw64-and-windows-10/7116/15 "2022-04-13T11:40:13Z")

</div>

Hi,

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:

```cpp
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:

```cpp
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?

regards,

Paulo

---

<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: [April 13, 2022, 12:48pm UTC](https://discourse.vtk.org/t/vtk-9-1-mingw64-and-windows-10/7116/16 "2022-04-13T12:48:55Z")

</div>

😅 😂 😂 😂 😂

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [April 13, 2022, 12:49pm UTC](https://discourse.vtk.org/t/vtk-9-1-mingw64-and-windows-10/7116/17 "2022-04-13T12:49:35Z")

</div>

What’s so funny?

---

<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: [April 13, 2022, 12:51pm UTC](https://discourse.vtk.org/t/vtk-9-1-mingw64-and-windows-10/7116/18 "2022-04-13T12:51:50Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [April 13, 2022, 12:53pm UTC](https://discourse.vtk.org/t/vtk-9-1-mingw64-and-windows-10/7116/19 "2022-04-13T12:53:55Z")

</div>

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

---

<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: [April 13, 2022, 1:07pm UTC](https://discourse.vtk.org/t/vtk-9-1-mingw64-and-windows-10/7116/20 "2022-04-13T13:07:41Z")

</div>

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

 ![image](https://discourse.vtk.org/uploads/default/original/2X/a/ad40da170c05a6287809ebdfcb1a9498a4c5a776.png)  
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 ,

 ![image](https://discourse.vtk.org/uploads/default/original/2X/b/bc4a8ddd264d00a43e292aa879f148ed4ad4dd17.png)

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

 ![image](https://discourse.vtk.org/uploads/default/original/2X/e/efec11f473005eede01019f193856651708a913e.png)

---

<div class="post-metadata">

### Author: ![lucidBrot](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lucidbrot/32/4732_2.png) [@lucidBrot](https://discourse.vtk.org/u/lucidBrot)
#### Post date: [April 26, 2022, 3:30pm UTC](https://discourse.vtk.org/t/vtk-9-1-mingw64-and-windows-10/7116/21 "2022-04-26T15:30:45Z")

</div>

> [@Andrea\_Gavana](#):
>
> Adding “-fcommon” as a C/CXX flag in CMake seems to make it work… but I’ll confirm if the build ends successfuly.

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

```cmake
  set(VTK_REQUIRED_CXX_FLAGS "${VTK_REQUIRED_CXX_FLAGS} -fcommon" )
  set(VTK_REQUIRED_C_FLAGS "${VTK_REQUIRED_C_FLAGS} -fcommon" )
  set(VTK_REQUIRED_EXE_LINKER_FLAGS "${VTK_REQUIRED_EXE_LINKER_FLAGS} -fcommon" )

```

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

```cmake
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fcommon" )
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fcommon" )
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fcommon" )

```

This is probably overkill, but it worked.

[Next page](https://discourse.vtk.org/t/vtk-9-1-mingw64-and-windows-10/7116.md?page=2)
