cmake
config_error
ai_generated
true
CMake Error: Feature cxx_std_17 is not available for compiler "GNU" version 4.8.
ID: cmake/compiler-feature-request-failed
90%Fix Rate
87%Confidence
1Evidence
2024-02-28First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| GCC 4.8 | active | — | — | — |
| GCC 5.4 | active | — | — | — |
| Clang 3.5 | active | — | — | — |
Root Cause
A target or project requests a C++ standard feature (e.g., cxx_std_17) that the installed compiler does not support due to its old version.
generic中文
目标或项目请求了一个 C++ 标准功能(例如 cxx_std_17),但安装的编译器版本太旧,不支持该功能。
Official Documentation
https://cmake.org/cmake/help/latest/manual/cmake-compile-features.7.htmlWorkarounds
-
95% success Upgrade the compiler to a version that supports C++17 (e.g., GCC 7 or later). Alternatively, set the target to a lower standard: set_target_properties(mytarget PROPERTIES CXX_STANDARD 14).
Upgrade the compiler to a version that supports C++17 (e.g., GCC 7 or later). Alternatively, set the target to a lower standard: set_target_properties(mytarget PROPERTIES CXX_STANDARD 14).
-
90% success Use target_compile_features(mytarget PRIVATE cxx_std_14) instead of cxx_std_17, and adjust code accordingly. Example: target_compile_features(mytarget PRIVATE cxx_std_14).
Use target_compile_features(mytarget PRIVATE cxx_std_14) instead of cxx_std_17, and adjust code accordingly. Example: target_compile_features(mytarget PRIVATE cxx_std_14).
-
85% success If compiler upgrade is not possible, use a compatibility layer or conditionally compile C++17 features: if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 7.0) target_compile_features(mytarget PRIVATE cxx_std_17) endif().
If compiler upgrade is not possible, use a compatibility layer or conditionally compile C++17 features: if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 7.0) target_compile_features(mytarget PRIVATE cxx_std_17) endif().
中文步骤
升级编译器到支持 C++17 的版本(例如 GCC 7 或更高)。或者,将目标设置为较低标准:set_target_properties(mytarget PROPERTIES CXX_STANDARD 14)。
使用 target_compile_features(mytarget PRIVATE cxx_std_14) 代替 cxx_std_17,并相应调整代码。示例:target_compile_features(mytarget PRIVATE cxx_std_14)。
如果无法升级编译器,使用兼容层或条件编译 C++17 特性:if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 7.0) target_compile_features(mytarget PRIVATE cxx_std_17) endif()。
Dead Ends
Common approaches that don't work:
-
80% fail
The compiler still does not support C++17; code using C++17 features will fail to compile with cryptic errors.
-
75% fail
CMake will still detect the compiler version and may produce warnings; also, compiler may not fully support C++17.