cmake config_error ai_generated true

error: use of undeclared identifier - C++17 feature used without C++17 enabled

ID: cmake/cxx-standard-not-propagated

Also available as: JSON · Markdown
85%Fix Rate
86%Confidence
3Evidence
2023-01-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
3 active

Root Cause

C++ standard not properly propagated to all targets.

generic

Workarounds

  1. 90% success Use target_compile_features with PUBLIC/INTERFACE
    target_compile_features(mylib PUBLIC cxx_std_17)
  2. 82% success Set CXX_STANDARD and CXX_STANDARD_REQUIRED on each target
    set_target_properties(app PROPERTIES CXX_STANDARD 17 CXX_STANDARD_REQUIRED ON)

Dead Ends

Common approaches that don't work:

  1. Set CMAKE_CXX_FLAGS directly with -std=c++17 75% fail

    Does not propagate to dependent targets and overrides other flags.

  2. Set CXX_STANDARD on the library but not the executable 70% fail

    Consumers need the standard requirement propagated via INTERFACE.