Skip to content

build: C++ standard checker does not work with C++11 supported compiler #27105

@Kumataro

Description

@Kumataro

System Information

OpenCV version: 4.x ( 3e43d0c )
Operating System / Platform: Ubuntu 24.04
Compiler & compiler version: GCC 13.3.0

Detailed description

C++ standard checker does not work with C++11 supported compiler .

HAVE_CXX11 is detected with CMAKE_CXX11_COMPILE_FEATURES.

if(CMAKE_CXX11_COMPILE_FEATURES)
set(HAVE_CXX11 ON)
endif()

CMAKE_CXX11_COMPILER_FEATURES means what features are supported the compiler. It doesnot means what features are available with this configuration.

See https://cmake.org/cmake/help/v3.31/manual/cmake-compile-features.7.html#manual:cmake-compile-features(7)

The CMAKE_C_COMPILE_FEATURES, CMAKE_CUDA_COMPILE_FEATURES , and CMAKE_CXX_COMPILE_FEATURES variables contain all features CMake knows are known to the compiler, regardless of language standard or compile flags needed to use them.

So if cmake -DCMAKE_CXX_STANDARD=98 runs with C++11 supported compiler, HAVE_CXX11 is ON.
Following C++ standard check will passed always for C++11 supported compiler.

if(NOT HAVE_CXX11)
message(FATAL_ERROR "OpenCV 4.x requires C++11")
endif()

Steps to reproduce

cmake -S opencv4 -B build4-main.CXX98 -DCMAKE_CXX_STANDARD=98 -GNinja

This cmake command finished without any error.

-- General configuration for OpenCV 4.12.0-dev =====================================
--   Version control:               4.11.0-264-g3e43d0cfca

--   C/C++:
--     Built as dynamic libs?:      YES
--     C++ standard:                98
--     C++ Compiler:                /usr/bin/c++  (ver 13.3.0)

-- -----------------------------------------------------------------
--
-- Configuring done (32.0s)
-- Generating done (0.3s)
-- Build files have been written to: /home/kmtr/work/build4-main.CXX98

Issue submission checklist

  • I report the issue, it's not a question
  • I checked the problem with documentation, FAQ, open issues, forum.opencv.org, Stack Overflow, etc and have not found any solution
  • I updated to the latest OpenCV version and the issue is still there
  • There is reproducer code and related data files (videos, images, onnx, etc)

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions