Skip to content

C++ modules: 'import std;' not working

I'm using CMake 3.29.20240512-g887311f and a clang/libc++ 18.1.3 build

with the following CMakeList.txt

cmake_minimum_required(VERSION 3.29.20240416 FATAL_ERROR)

project(test VERSION 1.0.0 LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED YES)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_EXPERIMENTAL_CXX_IMPORT_STD "0e5b6991-d74f-4b3d-a41c-cf096e0b2508")
set(CMAKE_CXX_MODULE_STD ON)

configure_file(config.h.in config.h)

add_executable(main)
target_sources(main PUBLIC
main.cpp)

Running cmake -B build -S . -G Ninja -DCMAKE_CXX_COMPILER=/usr/bin/clang++ -DCMAKE_CXX_FLAGS=-stdlib=libc++ results in:

-- Configuring done (0.0s) CMake Error in CMakeLists.txt: The "CXX_MODULE_STD" property on the target "main" requires that the "__CMAKE::CXX23" target exist, but it was not provided by the toolchain. Reason:

Experimental `import std` support not enabled when detecting toolchain

-- Generating done (0.0s) CMake Generate step failed. Build files cannot be regenerated correctly.

log.txt

Edited by Robert Knutsson
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information