After update cmake to use c++20 with set(CMAKE_CXX_STANDARD 20), the following errors appears when compiling the dependency leveldb

[ 11%] Built target glfw [ 15%] Built target raylib [ 16%] Built target fmt [ 16%] Building CXX object _deps/leveldb-build/CMakeFiles/leveldb.dir/util/env_posix.cc.o /home/natan/Projects/raylib-tutorial-2/03-classy_clash/build/_deps/leveldb-src/util/env_posix.cc: In constructor ‘leveldb::{anonymous}::SingletonEnv<EnvType>::SingletonEnv()’: /home/natan/Projects/raylib-tutorial-2/03-classy_clash/build/_deps/leveldb-src/util/env_posix.cc:840:53: error: ‘memory_order_relaxed’ is not a member of ‘std::memory_order’ 840 | env_initialized_.store(true, std::memory_order::memory_order_relaxed); | ^~~~~~~~~~~~~~~~~~~~ In file included from /usr/include/c++/13/cassert:44, from /home/natan/Projects/raylib-tutorial-2/03-classy_clash/build/_deps/leveldb-src/./util/posix_logger.h:13, from /home/natan/Projects/raylib-tutorial-2/03-classy_clash/build/_deps/leveldb-src/util/env_posix.cc:36: /home/natan/Projects/raylib-tutorial-2/03-classy_clash/build/_deps/leveldb-src/util/env_posix.cc: In static member function ‘static void leveldb::{anonymous}::SingletonEnv<EnvType>::AssertEnvNotInitialized()’: /home/natan/Projects/raylib-tutorial-2/03-classy_clash/build/_deps/leveldb-src/util/env_posix.cc:857:54: error: ‘memory_order_relaxed’ is not a member of ‘std::memory_order’ 857 | assert(!env_initialized_.load(std::memory_order::memory_order_relaxed)); | ^~~~~~~~~~~~~~~~~~~~ gmake[2]: *** [_deps/leveldb-build/CMakeFiles/leveldb.dir/build.make:580: _deps/leveldb-build/CMakeFiles/leveldb.dir/util/env_posix.cc.o] Error 1 gmake[1]: *** [CMakeFiles/Makefile2:425: _deps/leveldb-build/CMakeFiles/leveldb.dir/all] Error 2 gmake: *** [Makefile:156: all] Error 2

C++17 works fine.
What can I do to fix the build error with c++20?
Should I fork leveldb just to fix it?

wohlstad's user avatar

wohlstad

36.9k18 gold badges79 silver badges113 bronze badges

Natan Camargos's user avatar

5

The definition of std::memory_order changed in C++20, and the code isn't compatible with the new definition.

Old:

enum memory_order { memory_order_relaxed, // ... };

New:

enum class memory_order : /* ... */ { relaxed, // ... }; inline constexpr memory_order memory_order_relaxed = memory_order::relaxed; // ...

std::memory_order::memory_order_relaxed wasn't the intended way to refer to memory orders. You're supposed to use std::memory_order_relaxed or std::memory_order::relaxed.

HolyBlackCat's user avatar

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.