Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to use c++20 in cmake project

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?

like image 584
Tak Makoni Avatar asked Feb 22 '20 00:02

Tak Makoni


People also ask

Can you use CMake with C?

In the C/C++ ecosystem, the best tool for project configuration is CMake. CMake allows you to specify the build of a project, in files named CMakeLists. txt, with a simple syntax (much simpler than writing Makefiles).

Does CMake support C++ modules?

CMake currently does not support C++20 modules. See also the relevant issue in the CMake issue tracker. Note that supporting modules requires far more support from the build system than inserting a new compiler option.

Is CMake C or C++?

Both C++ CMake tools for Windows and Linux Development with C++ are required for cross-platform CMake development. For more information, see Install the C++ Linux workload in Visual Studio.


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.

like image 186
L. F. Avatar answered Oct 17 '22 03:10

L. F.