Compilation error with MSVC 2022: libtiff, libjpeg-turbo

I have these errors when building OpenCV contrib with MSVC 2022 :

  jcmaster.c
  jcomapi.c
C:\Users\AT09270\Documents\lib\opencv-4.6.0\cmake-build\3rdparty\libjpeg-turbo\jconfigint.h(37,20): fatal error C1017: invalid integer constant expression (compiling source file C:\U
sers\AT09270\Documents\lib\opencv-4.6.0\3rdparty\libjpeg-turbo\src\jccolor.c) [C:\Users\AT09270\Documents\lib\opencv-4.6.0\cmake-build\3rdparty\libjpeg-turbo\libjpeg-turbo.vcxproj]
C:\Users\AT09270\Documents\lib\opencv-4.6.0\cmake-build\3rdparty\libjpeg-turbo\jconfigint.h(37,20): fatal error C1017: invalid integer constant expression (compiling source file C:\U
sers\AT09270\Documents\lib\opencv-4.6.0\3rdparty\libjpeg-turbo\src\jchuff.c) [C:\Users\AT09270\Documents\lib\opencv-4.6.0\cmake-build\3rdparty\libjpeg-turbo\libjpeg-turbo.vcxproj]
  jcparam.c
  jcphuff.c
C:\Users\AT09270\Documents\lib\opencv-4.6.0\cmake-build\3rdparty\libjpeg-turbo\jconfigint.h(37,20): fatal error C1017: invalid integer constant expression (compiling source file C:\U
sers\AT09270\Documents\lib\opencv-4.6.0\3rdparty\libjpeg-turbo\src\jcmaster.c) [C:\Users\AT09270\Documents\lib\opencv-4.6.0\cmake-build\3rdparty\libjpeg-turbo\libjpeg-turbo.vcxproj]
  jcprepct.c
  jcsample.c
  jctrans.c
  jdapimin.c
  jdapistd.c
  jdatadst.c
C:\Users\AT09270\Documents\lib\opencv-4.6.0\cmake-build\3rdparty\libjpeg-turbo\jconfigint.h(37,20): fatal error C1017: invalid integer constant expression (compiling source file C:\U
sers\AT09270\Documents\lib\opencv-4.6.0\3rdparty\libjpeg-turbo\src\jcphuff.c) [C:\Users\AT09270\Documents\lib\opencv-4.6.0\cmake-build\3rdparty\libjpeg-turbo\libjpeg-turbo.vcxproj]
  jdatasrc.c
  jdcoefct.c
C:\Users\AT09270\Documents\lib\opencv-4.6.0\cmake-build\3rdparty\libjpeg-turbo\jconfigint.h(37,20): fatal error C1017: invalid integer constant expression (compiling source file C:\U
sers\AT09270\Documents\lib\opencv-4.6.0\3rdparty\libjpeg-turbo\src\jdapimin.c) [C:\Users\AT09270\Documents\lib\opencv-4.6.0\cmake-build\3rdparty\libjpeg-turbo\libjpeg-turbo.vcxproj]
  jdcolor.c
  jddctmgr.c
  jdhuff.c
  jdicc.c
  jdinput.c
C:\Users\AT09270\Documents\lib\opencv-4.6.0\cmake-build\3rdparty\libjpeg-turbo\jconfigint.h(37,20): fatal error C1017: invalid integer constant expression (compiling source file C:\U
sers\AT09270\Documents\lib\opencv-4.6.0\3rdparty\libjpeg-turbo\src\jdcolor.c) [C:\Users\AT09270\Documents\lib\opencv-4.6.0\cmake-build\3rdparty\libjpeg-turbo\libjpeg-turbo.vcxproj]
  jdmainct.c
  jdmarker.c
  jdmaster.c
  jdmerge.c
  jdphuff.c
C:\Users\AT09270\Documents\lib\opencv-4.6.0\cmake-build\3rdparty\libjpeg-turbo\jconfigint.h(37,20): fatal error C1017: invalid integer constant expression (compiling source file C:\U
sers\AT09270\Documents\lib\opencv-4.6.0\3rdparty\libjpeg-turbo\src\jdmainct.c) [C:\Users\AT09270\Documents\lib\opencv-4.6.0\cmake-build\3rdparty\libjpeg-turbo\libjpeg-turbo.vcxproj]
  jdpostct.c
C:\Users\AT09270\Documents\lib\opencv-4.6.0\cmake-build\3rdparty\libjpeg-turbo\jconfigint.h(37,20): fatal error C1017: invalid integer constant expression (compiling source file C:\U
sers\AT09270\Documents\lib\opencv-4.6.0\3rdparty\libjpeg-turbo\src\jdhuff.c) [C:\Users\AT09270\Documents\lib\opencv-4.6.0\cmake-build\3rdparty\libjpeg-turbo\libjpeg-turbo.vcxproj]
  jdsample.c
  jdtrans.c
C:\Users\AT09270\Documents\lib\opencv-4.6.0\cmake-build\3rdparty\libjpeg-turbo\jconfigint.h(37,20): fatal error C1017: invalid integer constant expression (compiling source file C:\U
sers\AT09270\Documents\lib\opencv-4.6.0\3rdparty\libjpeg-turbo\src\jdmerge.c) [C:\Users\AT09270\Documents\lib\opencv-4.6.0\cmake-build\3rdparty\libjpeg-turbo\libjpeg-turbo.vcxproj]
  jerror.c
  jfdctflt.c
  jfdctfst.c
C:\Users\AT09270\Documents\lib\opencv-4.6.0\cmake-build\3rdparty\libjpeg-turbo\jconfigint.h(37,20): fatal error C1017: invalid integer constant expression (compiling source file C:\U
sers\AT09270\Documents\lib\opencv-4.6.0\3rdparty\libjpeg-turbo\src\jdphuff.c) [C:\Users\AT09270\Documents\lib\opencv-4.6.0\cmake-build\3rdparty\libjpeg-turbo\libjpeg-turbo.vcxproj]
  jfdctint.c
  jidctflt.c

[...]

  tif_ojpeg.c
  tif_open.c
  tif_packbits.c
C:\Users\AT09270\Documents\lib\opencv-4.6.0\3rdparty\libtiff\tif_fax3.c(336,26): fatal error C1017: invalid integer constant expression [C:\Users\AT09270\Documents\lib\opencv-4.6.0\c
make-build\3rdparty\libtiff\libtiff.vcxproj]
  tif_pixarlog.c
  tif_predict.c
  tif_print.c
  tif_read.c
  tif_strip.c
  tif_swab.c
  tif_thunder.c
  tif_tile.c
  tif_version.c
  tif_warning.c
  tif_webp.c
  tif_write.c
  tif_zip.c
  tif_zstd.c
C:\Users\AT09270\Documents\lib\opencv-4.6.0\3rdparty\libtiff\tif_read.c(774,45): warning C4293: '<<': shift count negative or too big, undefined behavior [C:\Users\AT09270\Documents\
lib\opencv-4.6.0\cmake-build\3rdparty\libtiff\libtiff.vcxproj]
C:\Users\AT09270\Documents\lib\opencv-4.6.0\3rdparty\libtiff\tif_read.c(801,53): warning C4293: '<<': shift count negative or too big, undefined behavior [C:\Users\AT09270\Documents\
lib\opencv-4.6.0\cmake-build\3rdparty\libtiff\libtiff.vcxproj]
C:\Users\AT09270\Documents\lib\opencv-4.6.0\3rdparty\libtiff\tif_read.c(1212,45): warning C4293: '<<': shift count negative or too big, undefined behavior [C:\Users\AT09270\Documents
\lib\opencv-4.6.0\cmake-build\3rdparty\libtiff\libtiff.vcxproj]
C:\Users\AT09270\Documents\lib\opencv-4.6.0\3rdparty\libtiff\tif_read.c(1239,53): warning C4293: '<<': shift count negative or too big, undefined behavior [C:\Users\AT09270\Documents
\lib\opencv-4.6.0\cmake-build\3rdparty\libtiff\libtiff.vcxproj]
  tif_win32.c
C:\Users\AT09270\Documents\lib\opencv-4.6.0\3rdparty\libtiff\tif_zip.c(265,51): error C2059: syntax error: ')' [C:\Users\AT09270\Documents\lib\opencv-4.6.0\cmake-build\3rdparty\libti
ff\libtiff.vcxproj]
  alpha_dec.c
  buffer_dec.c

Configuration :

PS C:\Users\AT09270\Documents\lib\opencv-4.6.0\cmake-build> & "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" .. -D WITH_CUDA=ON -D CUDA_ARCH_BIN=7.5 -D CMAKE_INSTALL_PREFIX=../cmake-install-prefix  -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-4.6.0/modules
-- Selecting Windows SDK version 10.0.19041.0 to target Windows 10.0.22000.
-- The CXX compiler identification is MSVC 19.30.30711.2
-- The C compiler identification is MSVC 19.30.30711.2
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files/Microsoft Visual Studio/2022/Enterprise/VC/Tools/MSVC/14.30.30705/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files/Microsoft Visual Studio/2022/Enterprise/VC/Tools/MSVC/14.30.30705/bin/Hostx64/x64/cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detected processor: AMD64
-- Could NOT find PythonInterp (missing: PYTHON_EXECUTABLE) (Required is at least version "2.7")
-- Could NOT find PythonInterp (missing: PYTHON_EXECUTABLE) (Required is at least version "3.2")
-- libjpeg-turbo: VERSION = 2.1.2, BUILD = opencv-4.6.0-libjpeg-turbo
-- Could NOT find OpenJPEG (minimal suitable version: 2.0, recommended version >= 2.3.1). OpenJPEG will be built from sources
-- OpenJPEG: VERSION = 2.4.0, BUILD = opencv-4.6.0-openjp2-2.4.0
-- OpenJPEG libraries will be built from sources: libopenjp2 (version "2.4.0")
-- found Intel IPP (ICV version): 2020.0.0 [2020.0.0 Gold]
-- at: C:/Users/AT09270/Documents/lib/opencv-4.6.0/cmake-build/3rdparty/ippicv/ippicv_win/icv
-- found Intel IPP Integration Wrappers sources: 2020.0.0
-- at: C:/Users/AT09270/Documents/lib/opencv-4.6.0/cmake-build/3rdparty/ippicv/ippicv_win/iw
-- Could NOT find CUDNN (missing: CUDNN_LIBRARY CUDNN_INCLUDE_DIR) (Required is at least version "7.5")
-- CUDA detected: 11.8
-- CUDA: Using CUDA_ARCH_BIN=7.5
-- CUDA NVCC target flags: -gencode;arch=compute_75,code=sm_75;-D_FORCE_INLINES
-- CUDA: MSVS generator is detected. Disabling CMake re-run checks (CMAKE_SUPPRESS_REGENERATION=ON). You need to run CMake manually if updates are required.
-- Could not find OpenBLAS include. Turning OpenBLAS_FOUND off
-- Could not find OpenBLAS lib. Turning OpenBLAS_FOUND off
-- Found OpenMP_C: -openmp (found version "2.0")
-- Found OpenMP: TRUE (found version "2.0") found components: C
-- Looking for sgemm_
-- Looking for sgemm_ - not found
-- Could NOT find BLAS (missing: BLAS_LIBRARIES)
-- Could NOT find LAPACK (missing: LAPACK_LIBRARIES)
    Reason given by package: LAPACK could not be found because dependency BLAS could not be found.

-- Could NOT find JNI (missing: JAVA_AWT_LIBRARY JAVA_JVM_LIBRARY JAVA_INCLUDE_PATH JAVA_INCLUDE_PATH2 JAVA_AWT_INCLUDE_PATH)
-- VTK is not found. Please set -DVTK_DIR in CMake to VTK build directory, or to VTK install subdirectory with VTKConfig.cmake file
-- Module opencv_alphamat disabled because the following dependencies are not found: Eigen
-- freetype2:   NO
-- harfbuzz:    NO
-- Julia not found. Not compiling Julia Bindings.
-- Module opencv_ovis disabled because OGRE3D was not found
-- No preference for use of exported gflags CMake configuration set, and no hints for include/library directories provided. Defaulting to preferring an installed/exported gflags CMake configuration if available.
-- Failed to find installed gflags CMake configuration, searching for gflags build directories exported with CMake.
-- Failed to find gflags - Failed to find an installed/exported CMake configuration for gflags, will perform search for installed gflags components.
-- Failed to find gflags - Could not find gflags include directory, set GFLAGS_INCLUDE_DIR to directory containing gflags/gflags.h
-- Failed to find glog - Could not find glog include directory, set GLOG_INCLUDE_DIR to directory containing glog/logging.h
-- Module opencv_sfm disabled because the following dependencies are not found: Eigen Glog/Gflags
-- Tesseract:   NO
-- Allocator metrics storage type: 'long long'
-- Registering hook 'INIT_MODULE_SOURCES_opencv_dnn': C:/Users/AT09270/Documents/lib/opencv-4.6.0/modules/dnn/cmake/hooks/INIT_MODULE_SOURCES_opencv_dnn.cmake
-- opencv_dnn: filter out cuda4dnn source code
-- Excluding from source files list: <BUILD>/modules/dnn/layers/layers_common.rvv.cpp
-- imgcodecs: OpenEXR codec is disabled in runtime. Details: https://github.com/opencv/opencv/issues/21326
-- highgui: using builtin backend: WIN32UI
-- rgbd: Eigen support is disabled. Eigen is Required for Posegraph optimization
-- Building with NVIDIA Optical Flow API 2.0
-- Found 'misc' Python modules from C:/Users/AT09270/Documents/lib/opencv-4.6.0/modules/python/package/extra_modules
-- Found 'mat_wrapper;utils' Python modules from C:/Users/AT09270/Documents/lib/opencv-4.6.0/modules/core/misc/python/package
-- Found 'gapi' Python modules from C:/Users/AT09270/Documents/lib/opencv-4.6.0/modules/gapi/misc/python/package
--
-- General configuration for OpenCV 4.6.0 =====================================
--   Version control:               4.6.0
--
--   Extra modules:
--     Location (extra):            C:/Users/AT09270/Documents/lib/opencv_contrib-4.6.0/modules
--     Version control (extra):     4.6.0
--
--   Platform:
--     Timestamp:                   2022-11-03T20:20:37Z
--     Host:                        Windows 10.0.22000 AMD64
--     CMake:                       3.21.21080301-MSVC_2
--     CMake generator:             Visual Studio 17 2022
--     CMake build tool:            C:/Program Files/Microsoft Visual Studio/2022/Enterprise/MSBuild/Current/Bin/amd64/MSBuild.exe
--     MSVC:                        1930
--     Configuration:               Debug Release
--
--   CPU/HW features:
--     Baseline:                    SSE SSE2 SSE3
--       requested:                 SSE3
--     Dispatched code generation:  SSE4_1 SSE4_2 FP16 AVX AVX2 AVX512_SKX
--       requested:                 SSE4_1 SSE4_2 AVX FP16 AVX2 AVX512_SKX
--       SSE4_1 (18 files):         + SSSE3 SSE4_1
--       SSE4_2 (2 files):          + SSSE3 SSE4_1 POPCNT SSE4_2
--       FP16 (1 files):            + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 AVX
--       AVX (5 files):             + SSSE3 SSE4_1 POPCNT SSE4_2 AVX
--       AVX2 (33 files):           + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2
--       AVX512_SKX (8 files):      + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2 AVX_512F AVX512_COMMON AVX512_SKX
--
--   C/C++:
--     Built as dynamic libs?:      YES
--     C++ standard:                11
--     C++ Compiler:                C:/Program Files/Microsoft Visual Studio/2022/Enterprise/VC/Tools/MSVC/14.30.30705/bin/Hostx64/x64/cl.exe  (ver 19.30.30711.2)
--     C++ flags (Release):         /DWIN32 /D_WINDOWS /W4 /GR  /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi  /fp:precise     /EHa /wd4127 /wd4251 /wd4324 /wd4275 /wd4512 /wd4589 /MP  /MD /O2 /Ob2 /DNDEBUG
--     C++ flags (Debug):           /DWIN32 /D_WINDOWS /W4 /GR  /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi  /fp:precise     /EHa /wd4127 /wd4251 /wd4324 /wd4275 /wd4512 /wd4589 /MP  /MDd /Zi /Ob0 /Od /RTC1
--     C Compiler:                  C:/Program Files/Microsoft Visual Studio/2022/Enterprise/VC/Tools/MSVC/14.30.30705/bin/Hostx64/x64/cl.exe
--     C flags (Release):           /DWIN32 /D_WINDOWS /W3  /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi  /fp:precise     /MP   /MD /O2 /Ob2 /DNDEBUG
--     C flags (Debug):             /DWIN32 /D_WINDOWS /W3  /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi  /fp:precise     /MP /MDd /Zi /Ob0 /Od /RTC1
--     Linker flags (Release):      /machine:x64  /INCREMENTAL:NO
--     Linker flags (Debug):        /machine:x64  /debug /INCREMENTAL
--     ccache:                      NO
--     Precompiled headers:         YES
--     Extra dependencies:          cudart_static.lib nppc.lib nppial.lib nppicc.lib nppidei.lib nppif.lib nppig.lib nppim.lib nppist.lib nppisu.lib nppitc.lib npps.lib cublas.lib cufft.lib -LIBPATH:C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.8/lib/x64
--     3rdparty dependencies:
--
--   OpenCV modules:
--     To be built:                 aruco barcode bgsegm bioinspired calib3d ccalib core cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev datasets dnn dnn_objdetect dnn_superres dpm face features2d flann fuzzy gapi hfs highgui img_hash imgcodecs imgproc intensity_transform line_descriptor mcc ml objdetect optflow phase_unwrapping photo plot quality rapid reg rgbd saliency shape stereo stitching structured_light superres surface_matching text tracking ts video videoio videostab wechat_qrcode xfeatures2d ximgproc xobjdetect xphoto
--     Disabled:                    world
--     Disabled by dependency:      -
--     Unavailable:                 alphamat cvv freetype hdf java julia matlab ovis python2 python3 sfm viz
--     Applications:                tests perf_tests apps
--     Documentation:               NO
--     Non-free algorithms:         NO
--
--   Windows RT support:            NO
--
--   GUI:                           WIN32UI
--     Win32 UI:                    YES
--     VTK support:                 NO
--
--   Media I/O:
--     ZLib:                        build (ver 1.2.12)
--     JPEG:                        build-libjpeg-turbo (ver 2.1.2-62)
--     WEBP:                        build (ver encoder: 0x020f)
--     PNG:                         build (ver 1.6.37)
--     TIFF:                        build (ver 42 - 4.2.0)
--     JPEG 2000:                   build (ver 2.4.0)
--     OpenEXR:                     build (ver 2.3.0)
--     HDR:                         YES
--     SUNRASTER:                   YES
--     PXM:                         YES
--     PFM:                         YES
--
--   Video I/O:
--     DC1394:                      NO
--     FFMPEG:                      YES (prebuilt binaries)
--       avcodec:                   YES (58.134.100)
--       avformat:                  YES (58.76.100)
--       avutil:                    YES (56.70.100)
--       swscale:                   YES (5.9.100)
--       avresample:                YES (4.0.0)
--     GStreamer:                   NO
--     DirectShow:                  YES
--     Media Foundation:            YES
--       DXVA:                      YES
--
--   Parallel framework:            Concurrency
--
--   Trace:                         YES (with Intel ITT)
--
--   Other third-party libraries:
--     Intel IPP:                   2020.0.0 Gold [2020.0.0]
--            at:                   C:/Users/AT09270/Documents/lib/opencv-4.6.0/cmake-build/3rdparty/ippicv/ippicv_win/icv
--     Intel IPP IW:                sources (2020.0.0)
--               at:                C:/Users/AT09270/Documents/lib/opencv-4.6.0/cmake-build/3rdparty/ippicv/ippicv_win/iw
--     Lapack:                      NO
--     Eigen:                       NO
--     Custom HAL:                  NO
--     Protobuf:                    build (3.19.1)
--
--   NVIDIA CUDA:                   YES (ver 11.8, CUFFT CUBLAS)
--     NVIDIA GPU arch:             75
--     NVIDIA PTX archs:
--
--   cuDNN:                         NO
--
--   OpenCL:                        YES (NVD3D11)
--     Include path:                C:/Users/AT09270/Documents/lib/opencv-4.6.0/3rdparty/include/opencl/1.2
--     Link libraries:              Dynamic load
--
--   Python (for build):            NO
--
--   Java:
--     ant:                         NO
--     JNI:                         NO
--     Java wrappers:               NO
--     Java tests:                  NO
--
--   Install to:                    C:/Users/AT09270/Documents/lib/opencv-4.6.0/cmake-install-prefix
-- -----------------------------------------------------------------
--
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/AT09270/Documents/lib/opencv-4.6.0/cmake-build

Why ?

1 Like

I’ve tried your cmake command and I am not seeing that error. The only obvious difference I can see is your using CUDA 11.8 with MSVC Enterprise 1930 and I am using 11.7 with Community 1933. That said the support table indicates that this should not be a problem.

How long during the build process before you see these errors and are you building Debug or Release?

Can you confirm line 265 and column 51 :
(unsigned long) tif->tif_row, (TIFF_UINT64_T) occ);

There is no ) in my code

may be reason is Visual Studio Feedback

1 Like

I am building release.
The errors are coming almost immediately (5 seconds) after starting the build.
And I have a temporary work-around : WITH_JPEG=OFF and WITH_TIFF=OFF.

I will check the source when I can and try another version of MSVC.

I didn’t notice you had the whole output for the error the suggestion from @laurent.berger would be the first thing to try.