how to use c++20 in cmake project

15,805

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.

Share:
15,805

Related videos on Youtube

Tak Makoni
Author by

Tak Makoni

Updated on June 04, 2022

Comments

  • Tak Makoni
    Tak Makoni almost 2 years

    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?

    • Hunter Kohler
      Hunter Kohler almost 3 years
      Good news! MSVC now supports text formatting.
  • Ayxan Haqverdili
    Ayxan Haqverdili about 4 years
    I wonder why this is the case. Is it that hard to implement <format>? More complex parts like "concepts" seem to be already supported by most compilers.
  • L. F.
    L. F. about 4 years
    @Ayxan Concepts started as a TS; many compilers have worked on it several years ago. <format>, however, is mostly just the fmt library standardized.
  • Martin
    Martin over 3 years
    I came accross this post, searching for a different c++20 feature being supported and followed your link. The table changed a little, but Text formatting is still all red. @Tak Makoni: in case you use MSVC, here is a list of supported features per MSVC version: docs.microsoft.com/en-us/cpp/overview/…