# VTK 9.4 debug build fails with MSVC due to "image size ... exceeds maximum allowable size"

**URL:** https://discourse.vtk.org/t/vtk-9-4-debug-build-fails-with-msvc-due-to-image-size-exceeds-maximum-allowable-size/15520
**Category:** Development
**Created:** [April 20, 2025, 2:27am UTC](https://discourse.vtk.org/t/vtk-9-4-debug-build-fails-with-msvc-due-to-image-size-exceeds-maximum-allowable-size/15520 "2025-04-20T02:27:21Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![lassoan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lassoan/32/50_2.png) [@lassoan](https://discourse.vtk.org/u/lassoan)
#### Post date: [April 20, 2025, 2:27am UTC](https://discourse.vtk.org/t/vtk-9-4-debug-build-fails-with-msvc-due-to-image-size-exceeds-maximum-allowable-size/15520/1 "2025-04-20T02:27:22Z")

</div>

Debug build of VTK-9.4 fail on Windows if `VTK_ENABLE_KITS` is enabled, with this error:

> CommonCore-objects.dir\Debug\CommonCore-objects.lib : fatal error LNK1248: image size (10098384C) exceeds maximum allowable size (FFFFFFFF) [C:\D\VTK-bin\Common\Core\CommonCore-objects.vcxproj]

This is a problem, because [we can no longer build 3D Slicer in debug mode on Windows](https://discourse.slicer.org/t/vtk-build-fails-on-windows-in-debug-mode/42590).

Full build command:

```auto
cmake c:\D\VTK -G "Visual Studio 17 2022" -T "v143" -DVTK_ENABLE_KITS:BOOL=ON
cmake --build . --config Debug -- /m

```

VTK 9.2 was built successfully with the same options. The issue seems to be that `CommonCore` is actually huge now. Size of `VTK-bin\Common\Core\CommonCore.dir\Debug` is 7.9GB in VTK-9.4, while it was 3.1GB in VTK-9.2.

The difference is about 230 extra files in `VTK-bin\Common\Core\CommonCore.dir\Debug` folder:

```auto
vtkAffineArrayInstantiate_<type>.obj
vtkCompositeArrayInstantiate_<type>.obj
vtkConstantArrayInstantiate_<type>.obj
vtkIndexedArrayInstantiate_<type>.obj
vtkStdFunctionArrayInstantiate_<type>.obj
vtkStructuredPointArrayInstantiate_<type>.obj
vtkTypedDataArrayInstantiate_<type>.obj
vtkAffine<type>Array.obj
vtkComposite<type>Array.obj
vtkConstant<type>Array.obj
vtkIndexed<type>Array.obj
vtkAffineImplicitBackendInstantiate_<type>.obj
vtkCompositeImplicitBackendInstantiate_<type>.obj
vtkConstantImplicitBackendInstantiate_<type>.obj
vtkIndexedImplicitBackendInstantiate_<type>.obj
vtkStructuredPointBackendInstantiate_<type>.obj
vtkDataArray<operation>.obj

```

I’ve tried to add `-DVTK_DISPATCH_AFFINE_ARRAYS:BOOL=OFF -DVTK_DISPATCH_CONSTANT_ARRAYS:BOOL=OFF -DVTK_DISPATCH_STD_FUNCTION_ARRAYS:BOOL=OFF -DVTK_DISPATCH_STRUCTURED_POINT_ARRAYS:BOOL=OFF` but it resulted in many build errors similar to this:

```txt
35>C:\D\S4D\VTK\Common\Core\vtkDataArray_GetTuples_ids.cxx(24,33): error C2039: 'DataArrayTupleRange': is not a member of 'vtk'
35> C:\D\S4D\VTK\Common\Core\vtkAOSDataArrayTemplate.h(29,11):
35> see declaration of 'vtk'
35> C:\D\S4D\VTK\Common\Core\vtkDataArray_GetTuples_ids.cxx(24,33):
35> the template instantiation context (the oldest one first) is
35> C:\D\S4D\VTK\Common\Core\vtkDataArray_GetTuples_ids.cxx(66,5):
35> see reference to function template instantiation 'void `anonymous-namespace'::GetTuplesFromListWorker::operator ()<vtkDataArray,vtkDataArray>(Array1T *,Array2T *) const' being compiled
35> with
35> [
35> Array1T=vtkDataArray,
35> Array2T=vtkDataArray
35> ]

```

Would it be possible to move back implicit arrays into their own `CommonImplicitArrays` component as it was before?

If that was impractical, could someone provide CMake flags that allow building VTK without implicit arrays?

@spyridon97 @ben.boeckel

---

<div class="post-metadata">

### Author: ![spyridon97](https://discourse.vtk.org/user_avatar/discourse.vtk.org/spyridon97/32/7069_2.png) [@spyridon97](https://discourse.vtk.org/u/spyridon97)
#### Post date: [April 21, 2025, 4:34pm UTC](https://discourse.vtk.org/t/vtk-9-4-debug-build-fails-with-msvc-due-to-image-size-exceeds-maximum-allowable-size/15520/2 "2025-04-21T16:34:09Z")

</div>

By default, all the implicit arrays are not dispatched with the exception of vtkStructuredPointsArray which is used internally in vtkImageData, vtkRectilinearGrid.

They can’t be deactivated from compiling since they are part of common core.

We moved it into common core, because it created a lot of extra includes and spagheti code, if this does not exist, use the other, and such. Plus all arrays should belong to the same module. I tried to create a CommonArrays module, but it did not work because of internal cyclic dependencies with vtkVariant which in turn depends on vtkInformationKey (or something like that, it’s been 2 years since i worked on this).

I personally see 2 potential solutions.

1. Actually, implement the CommonArray module, but i don’t know if that will affect the kits compilation.
2. Understand why windows does not work and Linux does (i hope). Is there something that we can pass to the compiler to reduce the size, or something that linux passed which reduces the size?

---

<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 21, 2025, 7:08pm UTC](https://discourse.vtk.org/t/vtk-9-4-debug-build-fails-with-msvc-due-to-image-size-exceeds-maximum-allowable-size/15520/3 "2025-04-21T19:08:10Z")

</div>

Hello,

Perhaps enabling some optimization in debug mode, by setting `CMAKE_CXX_FLAGS_DEBUG` to `/O2` when configuring the build with CMake. Reference: [/O options (Optimize code) | Microsoft Learn](https://learn.microsoft.com/en-us/cpp/build/reference/o-options-optimize-code?view=msvc-170). Try to find one that reduces the executable size to just under the limit while minimizing impact on debugging capabilities or profiling accuracy.

best,

PC

---

<div class="post-metadata">

### Author: ![spyridon97](https://discourse.vtk.org/user_avatar/discourse.vtk.org/spyridon97/32/7069_2.png) [@spyridon97](https://discourse.vtk.org/u/spyridon97)
#### Post date: [April 21, 2025, 8:25pm UTC](https://discourse.vtk.org/t/vtk-9-4-debug-build-fails-with-msvc-due-to-image-size-exceeds-maximum-allowable-size/15520/4 "2025-04-21T20:25:32Z")

</div>

A quick way to test your idea is to try RelWithDebInfo.

---

<div class="post-metadata">

### Author: ![lassoan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lassoan/32/50_2.png) [@lassoan](https://discourse.vtk.org/u/lassoan)
#### Post date: [April 21, 2025, 10:30pm UTC](https://discourse.vtk.org/t/vtk-9-4-debug-build-fails-with-msvc-due-to-image-size-exceeds-maximum-allowable-size/15520/5 "2025-04-21T22:30:52Z")

</div>

`RelWithDebInfo` and other optimized builds are not replacements for a `Debug` build, as they severely limit debugging (methods are removed, lines are skipped, code is not executed in order, variables are inaccessible, etc.).

> By default, all the implicit arrays are not dispatched with the exception of vtkStructuredPointsArray which is used internally in vtkImageData, vtkRectilinearGrid.

I see that most of the `VTK_DISPATCH_..._ARRAYS` CMake variables are set to `OFF`, but I’m not sure if they are effective.

As I wrote above, when I built with default options, .obj files were created not just `vtkStructuredPointArray` (447MB of .obj files), but also for `vtkAffineArray` (413MB), `vtkCompositeArray` (692MB), `vtkConstantArray` (241MB), `vtkIndexedArray` (717MB), `vtkStdFunctionArray` (241MB), `vtkTypedDataArray` (233MB).

Considering their enormous size, would it be possible to add CMake options to remove instantiations of these rarely used types?

---

<div class="post-metadata">

### Author: ![spyridon97](https://discourse.vtk.org/user_avatar/discourse.vtk.org/spyridon97/32/7069_2.png) [@spyridon97](https://discourse.vtk.org/u/spyridon97)
#### Post date: [April 22, 2025, 3:22pm UTC](https://discourse.vtk.org/t/vtk-9-4-debug-build-fails-with-msvc-due-to-image-size-exceeds-maximum-allowable-size/15520/6 "2025-04-22T15:22:02Z")

</div>

We will discuss how to resolve this issue internally, and let you know.

---

<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: [April 22, 2025, 3:54pm UTC](https://discourse.vtk.org/t/vtk-9-4-debug-build-fails-with-msvc-due-to-image-size-exceeds-maximum-allowable-size/15520/7 "2025-04-22T15:54:01Z")

</div>

> [@lassoan](#):
>
> Debug build of VTK-9.4 fail on Windows if `VTK_ENABLE_KITS` is enabled, with this error

That limit smells of a 32bit build. It looks like it _should_ be, but could you please confirm that this is indeed a 64-bit build.

---

<div class="post-metadata">

### Author: ![lassoan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lassoan/32/50_2.png) [@lassoan](https://discourse.vtk.org/u/lassoan)
#### Post date: [April 22, 2025, 4:51pm UTC](https://discourse.vtk.org/t/vtk-9-4-debug-build-fails-with-msvc-due-to-image-size-exceeds-maximum-allowable-size/15520/8 "2025-04-22T16:51:31Z")

</div>

Yes, it is a 64-bit build. See the full build command in the first post.

---

<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: [June 5, 2025, 3:16pm UTC](https://discourse.vtk.org/t/vtk-9-4-debug-build-fails-with-msvc-due-to-image-size-exceeds-maximum-allowable-size/15520/9 "2025-06-05T15:16:55Z")

</div>

Fixed in VTK master 🙂

[https://gitlab.kitware.com/vtk/vtk/-/merge\_requests/12133](https://gitlab.kitware.com/vtk/vtk/-/merge_requests/12133)

Thanks a lot @alexy.pellegrini !

---

<div class="post-metadata">

### Author: ![lassoan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lassoan/32/50_2.png) [@lassoan](https://discourse.vtk.org/u/lassoan)
#### Post date: [June 7, 2025, 2:14pm UTC](https://discourse.vtk.org/t/vtk-9-4-debug-build-fails-with-msvc-due-to-image-size-exceeds-maximum-allowable-size/15520/10 "2025-06-07T14:14:10Z")

</div>

Awesome, thank you very much for everyone’s work on this!
