Build error: VTK 9.6.0 rc3, vtkResourceStream.cxx line79, std::min, MSVS 14.44/x86/Debug

Hi,

I tried to build VTK 9.6.0 rc3 for Win32/x86 and Debug target, but the build failed.

In vtkResourceStream.cxx, std::min is called with parameters of different types.

260208_vtk_9.6.0.rc3\IO\Core\vtkResourceStream.cxx(79,46): error C2672: 'std::min': no matching overloaded function found
192>    C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\include\utility(109,26):
192>    could be '_Ty std::min(std::initializer_list<_Elem>)'
192>        C:\Users\built\libs\vtk\260208_vtk_9.6.0.rc3\IO\Core\vtkResourceStream.cxx(79,46):
192>        '_Ty std::min(std::initializer_list<_Elem>)': expects 1 arguments - 2 provided
192>    C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\include\utility(106,26):
192>    or       '_Ty std::min(std::initializer_list<_Elem>,_Pr)'
192>        C:\Users\built\libs\vtk\260208_vtk_9.6.0.rc3\IO\Core\vtkResourceStream.cxx(79,46):
192>        '_Ty std::min(std::initializer_list<_Elem>,_Pr)': could not deduce template argument for 'std::initializer_list<_Elem>' from 'const ptrdiff_t'
192>    C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\include\utility(98,6):
192>    or       'const _Ty &std::min(const _Ty &,const _Ty &) noexcept(<expr>)'


After casting ‘available’ to (long long) the VTK built Okay.

We need to #define NOMINMAX before including windows.h.

Can you apply this patch and see how many other places need an update as well (same diff should fix it, right at the top of the main .cxx file bing compiled before the first #include).

diff --git i/IO/Core/vtkResourceStream.cxx w/IO/Core/vtkResourceStream.cxx
index 4790d63f03..c9c6e9535d 100644
--- i/IO/Core/vtkResourceStream.cxx
+++ w/IO/Core/vtkResourceStream.cxx
@@ -1,5 +1,11 @@
 // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
 // SPDX-License-Identifier: BSD-3-Clause
+
+#ifdef _WIN32
+// Disable min/max macros from `windows.h`.
+#define NOMINMAX
+#endif
+
 #include "vtkResourceStream.h"

 #include <algorithm>

Ah, I see that after your fix everything else was fine now. I’ll submit this diff.

https://gitlab.kitware.com/vtk/vtk/-/merge_requests/12902

Hi ,

your code does not fix the error. This error is not about min/max macros.

std::min is a template and requies both its params to be of the same type. On x86

std::copy_n(parent_type::gptr(), (std::min)(available, count), str);

available is std::ptrdiff_t  == int       == 4 bytes (on x86, 8 bytes on x64)

count     is std::streamsize == long long == 8 bytes

this should fix it: https://gitlab.kitware.com/vtk/vtk/-/merge_requests/12903

error

vtkResourceStream.cxx(80,18): error C1075: ‘(’: no matching token found

fixed.

1 Like