Search code examples
c++clangmingwc++20c++-chrono

No type named 'time_zone' in namespace 'std::chrono'


I'm trying to compile a project on windows under MinGW with Clang 16.0.4.

As a result, I get this error: error: no type named 'time_zone' in namespace 'std::chrono'

In my CMakeLists I have this set:

set (CMAKE_CXX_STANDARD 20)
set (CMAKE_C_STANDARD 17)

Also, I've tried changing that gnu++20 to normal c++20 standard with CMAKE_CXX_EXTENSIONS OFF, but this doesn't make any difference in the end.

What should I do? Maybe consider some non-standard replacement for time zones?


Solution

  • You need the g++ 13 standard library to get std::chrono::time_zone. You most likely have an older version of the g++ standard library installed - which is what clang++ uses by default.

    The standard library provided by clang++16.0.4 itself (-stdlib=libc++) does not include time_zone either.

    Options:

    • Install a newer g++ and make clang++ use its standard library.
    • Install date.h + tz.h and use that.
    • Build clang++ and its standard library from the latest source. That includes std::chrono::time_zone.