how to use c++20 in cmake project

Viewed 23343

I want to use the header available in c++20.

I am using the most up to date release of cmake.

my CMakeFiles looks like

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_BUILD_TYPE debug)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++20")

i am using clang 9 as my compiler.

however i am getting the following error when including :

fatal error: 'format' file not found
#include <format>

i have also used the flag -std=c++2a, with no effect. In short, i feel i have missed something important here. Im a little new to cmake, any help?

1 Answers

According to the C++ compiler support page (archive) on cppreference, none of the mainstream compilers currently support the C++20 <format> functionalities.

enter image description here

Therefore, you can't currently use #include <format>. Consider using the {fmt} library for now, on which the C++20 <format> library is based. It is famous for its high safety and efficiency.

Related