How to build vtk

I would like to build vtk for two purposes:

  • Run examples/come up with own examples in C++
  • Contribute to development in case I find a bug or possible enhancement

So far I have gone through the following steps:

  • Forked VTK to own GitLab account
  • Did a git clone own_account_url on local machine
  • Downloaded and installed CMake
  • Downloaded and installed Mingw-w64 from sourceforge
  • added Mingw-w64 directory to PATH
  • Created a \bin folder inside local clone of VTK repo
  • Ran CMake with .\vtk as source folder and .\vtk\bin as binary folder, using Code Blocks Mingw generator

This seemed to work, generating a VTK.cbp file which I was able to open using CodeBlocks. I then built the project by hitting Ctrl+F9. After building for 40 minutes I got an error:

C:\Users\aboufira\AppData\Local\Temp\ccrGE4Ag.s: Fatal error: can't write 40 bytes to section .text of CMakeFiles\CommonCore.dir\vtkDataArray.cxx.obj: 'File too big'
C:/PROGRA~2/MINGW-~1/I686-8~1.0-P/mingw32/bin/../lib/gcc/i686-w64-mingw32/8.1.0/../../../../i686-w64-mingw32/bin/as.exe: CMakeFiles\CommonCore.dir\vtkDataArray.cxx.obj: too many sections (42814)
C:\Users\aboufira\AppData\Local\Temp\ccrGE4Ag.s: Fatal error: can't close CMakeFiles\CommonCore.dir\vtkDataArray.cxx.obj: File too big
mingw32-make.exe[2]: *** [Common\Core\CMakeFiles\CommonCore.dir\build.make:996: Common/Core/CMakeFiles/CommonCore.dir/vtkDataArray.cxx.obj] Error 1
mingw32-make.exe[1]: *** [CMakeFiles\Makefile2:8126: Common/Core/CMakeFiles/CommonCore.dir/all] Error 2
mingw32-make.exe: *** [D:/github_projects/vtk/bin/Makefile:157: all] Error 2

Does anyone know why this occurs and how I can fix it? Thanks.

In order to build VTK, please follow the instructions here :

You will notice that Mingw is not listed as a supported compiler.
On windows we recommend visual studio + ninja. But pure visual studio is also supported.

Once you are able to build VTK, please follow this guide to be able to contribute :

Hi @mwestphal thanks for your response. I will probably continue with VS. Just out of curiosity though, the instructions state the following:

Note that Unix-like environments such as Cygwin and MinGW are not officially supported

Does that mean these types of environments actually won’t work? If so why not? How is it that a valid .cbp file is generated with CMake?

They are not tested, so we assume they don’t work, but maybe they do.
You will be on your own though, which I will not recommend as it looks like this is your first time compiling VTK.

As for the .cbp file, CMake doesn’t care that VTK is not supporting it officially.

If you are looking to work in a Unix-like environment, why not using Linux directly ?

I see. No I’m not looking to work in a Unix-like environment as I use Windows. I was able to build the project again using CMake and now have a working VS2019 solution. A couple of follow up questions:

The visual studio only guide is here :

VTK_BUILD_TESTING build the tests visible here :
VTK_BUILD_EXAMPLES build the examples :

Thanks. Those are good resources. I was able to successfully build the Release configuration (though it does take a while) and am now trying to “test with an example” as outlined by

I do notice that the repository already contains an “Examples” directory, but that the examples in here do not correspond with the examples shown in

Why are these examples different? Thanks.

VTK_BUILD_EXAMPLES build the example in the source, but the link I provided is more easy to navigate and copy examples from.

1 Like