clang++ --version
Ubuntu clang version 21.1.7 (++20251127113503+9ed1927442a4-1~exp1~20251127113518.64)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/lib/llvm-21/bin
clang++ -print-file-name=libc++.modules.json
/lib/x86_64-linux-gnu/libc++.modules.json
clang++ -print-file-name=libstdc++.modules.json
libstdc++.modules.json
cmake --version
cmake version 4.2.0
CMake suite maintained and supported by Kitware (kitware.com/cmake).
ninja --version
1.13.0
cmake --preset dev --fresh --log-level=VERBOSE
CMake Warning (dev) at cmake/prelude.cmake:58 (if):
Preset CMake variables:
BUILD_MCSS_DOCS:BOOL="FALSE"
BUILD_SHARED_LIBS:BOOL="TRUE"
CMAKE_BUILD_TYPE="Release"
CMAKE_CONFIGURATION_TYPES="RelWithDebInfo;Release;Debug"
CMAKE_CXX_EXTENSIONS:BOOL="TRUE"
CMAKE_CXX_FLAGS_DEBUG="-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3 -fstack-protector-strong -fcf-protection=full -fstack-clash-protection -Wall -Wextra -Wpedantic -Wno-conversion -Wno-sign-conversion -Wcast-qual -Wformat=2 -Wundef -Wno-float-equal -Wshadow -Wcast-align -Wunused -Wnull-dereference -Wdouble-promotion -Wno-implicit-fallthrough -Wextra-semi -Woverloaded-virtual -Wnon-virtual-dtor -Wno-old-style-cast"
CMAKE_CXX_STANDARD="23"
CMAKE_CXX_STANDARD_REQUIRED:BOOL="TRUE"
CMAKE_EXE_LINKER_FLAGS_DEBUG="-Wl,--allow-shlib-undefined,--as-needed,-z,noexecstack,-z,relro,-z,now"
CMAKE_EXPORT_COMPILE_COMMANDS:BOOL="TRUE"
CMAKE_INSTALL_PREFIX:PATH="/__w/cmake-init-modules/cmake-init-modules/stagedir"
uninitialized variable 'CMAKE_CXX_STDLIB_MODULES_JSON'
Call Stack (most recent call first):
CMakeLists.txt:4 (include)
This warning is for project developers. Use -Wno-dev to suppress it.
CMAKE_MESSAGE_LOG_LEVEL="VERBOSE"
CMAKE_PREFIX_PATH:STRING="/__w/cmake-init-modules/cmake-init-modules/stagedir"
CMAKE_SHARED_LINKER_FLAGS_DEBUG="-Wl,--allow-shlib-undefined,--as-needed,-z,noexecstack,-z,relro,-z,now"
CMAKE_VERIFY_INTERFACE_HEADER_SETS:BOOL="TRUE"
cmake-init-modules_DEVELOPER_MODE:BOOL="TRUE"
Preset environment variables:
CPM_USE_LOCAL_PACKAGES="OFF"
-- CXXFLAGS=-stdlib=libc++
-- The CXX compiler identification is Clang 21.1.7
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/clang++ - skipped
-- Detecting CXX compile features
CMake Warning (dev) at /github/home/cmake/cmake-4.2.0-linux-x86_64/share/cmake-4.2/Modules/Compiler/CMakeCommonCompilerMacros.cmake:248 (cmake_language):
CMake's support for `import std;` in C++23 and newer is experimental. It
is meant only for experimentation and feedback to CMake developers.
Call Stack (most recent call first):
/github/home/cmake/cmake-4.2.0-linux-x86_64/share/cmake-4.2/Modules/CMakeDetermineCompilerSupport.cmake:113 (cmake_create_cxx_import_std)
/github/home/cmake/cmake-4.2.0-linux-x86_64/share/cmake-4.2/Modules/CMakeTestCXXCompiler.cmake:83 (CMAKE_DETERMINE_COMPILER_SUPPORT)
CMakeLists.txt:7 (project)
This warning is for project developers. Use -Wno-dev to suppress it.
-- Detecting CXX compile features - done
-- CMAKE_CXX_COMPILER_IMPORT_STD=23;26
-- CMAKE_CXX_MODULE_STD=ON
-- ALGO_USE_MODULES=ON
-- CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES=/usr/lib/llvm-21/include/c++/v1;/usr/lib/llvm-21/lib/clang/21/include;/usr/local/include;/usr/include/x86_64-linux-gnu;/usr/include
-- Performing Test COMPILER_HAS_HIDDEN_VISIBILITY
CMake Error at /__w/cmake-init-modules/cmake-init-modules/build/dev/CMakeFiles/4.2.0/CMakeCXXCompiler.cmake:111 (target_sources):
Cannot find source file:
/lib/share/libc++/v1/std.cppm
Call Stack (most recent call first):
/__w/cmake-init-modules/cmake-init-modules/build/dev/CMakeFiles/CMakeScratch/TryCompile-mFgvN7/CMakeLists.txt:2 (project)
CMake Error at /__w/cmake-init-modules/cmake-init-modules/build/dev/CMakeFiles/4.2.0/CMakeCXXCompiler.cmake:103 (add_library):
No SOURCES given to target: __cmake_cxx23
Call Stack (most recent call first):
/__w/cmake-init-modules/cmake-init-modules/build/dev/CMakeFiles/CMakeScratch/TryCompile-mFgvN7/CMakeLists.txt:2 (project)
CMake Error at /__w/cmake-init-modules/cmake-init-modules/build/dev/CMakeFiles/4.2.0/CMakeCXXCompiler.cmake:127 (add_library):
No SOURCES given to target: __cmake_cxx26
Call Stack (most recent call first):
/__w/cmake-init-modules/cmake-init-modules/build/dev/CMakeFiles/CMakeScratch/TryCompile-mFgvN7/CMakeLists.txt:2 (project)
CMake Error at /github/home/cmake/cmake-4.2.0-linux-x86_64/share/cmake-4.2/Modules/Internal/CheckSourceCompiles.cmake:104 (try_compile):
Failed to generate test project build system.
Call Stack (most recent call first):
/github/home/cmake/cmake-4.2.0-linux-x86_64/share/cmake-4.2/Modules/Internal/CheckCompilerFlag.cmake:18 (cmake_check_source_compiles)
/github/home/cmake/cmake-4.2.0-linux-x86_64/share/cmake-4.2/Modules/CheckCompilerFlag.cmake:124 (cmake_check_compiler_flag)
/github/home/cmake/cmake-4.2.0-linux-x86_64/share/cmake-4.2/Modules/GenerateExportHeader.cmake:515 (check_compiler_flag)
/github/home/cmake/cmake-4.2.0-linux-x86_64/share/cmake-4.2/Modules/GenerateExportHeader.cmake:693 (_test_compiler_hidden_visibility)
CMakeLists.txt:43 (generate_export_header)
-- Configuring incomplete, errors occurred!
make: *** [GNUmakefile:58: .init] Error 1
Error: Process completed with exit code 2.
It looks like the toolchain’s JSON file doesn’t specify sources correctly. I’d need the layout of the toolchain and its modules.json file to be able to do anything more.
Hi @ben.boeckel ! I see the same problems for clang since 22.1.6, cmake 4.3.2, and llvm Ubuntu 24.04 debian packages
The files layout is
std.pcm installed into /usr/lib/llvm-22/share/libc++/v1/std.cppm
libc++.modules.json is installed (from libc++-22-dev package) into /usr/lib/x86_64-linux-gnu/libc++.modules.json and /usr/lib/llvm-22/lib/libc++.modules.json (the symlink to first path)
clang++-22 -print-file-name=libc++.modules.json output is /lib/x86_64-linux-gnu/libc++.modules.json
the libc++.modules.json contents is
{
"version": 1,
"revision": 1,
"modules": [
{
"logical-name": "std",
"source-path": "../share/libc++/v1/std.cppm",
"is-std-library": true,
"local-arguments": {
"system-include-directories": [
"../share/libc++/v1"
]
}
},
{
"logical-name": "std.compat",
"source-path": "../share/libc++/v1/std.compat.cppm",
"is-std-library": true,
"local-arguments": {
"system-include-directories": [
"../share/libc++/v1"
]
}
}
]
}
I guess CMake try to find std.cppm relative to /lib/x86_64-linux-gnu/libc++.modules.json directory and come up with /lib/share/libc++/v1/std.compat.cppm which does not exist
The solution (since CMake 4.2) is to explicitly set -DCMAKE_CXX_STDLIB_MODULES_JSON=/usr/lib/llvm-22/lib/libc++.modules.json
But I am not sure the solution is intended because import std does not work by default
Do you know whether it is a CMake problem or clang or llvm debian package?
I feel like packaging…but LLVM might need to handle multi-arch layouts and recompute the number of ../ bits to use. But not reporting /usr seems like either a UsrMove issue (e.g., still putting /bin in PATH) or a packaging problem with specifying the prefix properly.