Currently, import std doesn’t work on Windows. It fails both in a pure Visual Studio environment (using the CMake and Clang provided by Visual Studio) and with the latest versions of LLVM and CMake built from source. I’ve opened an issue about this, but it seems to be ignored—similar problems were reported over a year ago with no resolution.
If anyone can look into this, it would be greatly appreciated. It’s incredibly frustrating to see this still broken after so many promising conference talks.
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:
Only `libc++` and `libstdc++` are supported
-- Generating done (0.0s)
If you do it right, it works.
On Windows with MSVC 19.43.34808.0, but you need CMake v4.0.3 and Ninja generator:
Run export hostSystemName=Windows
MINGW64_NT-10.0-20348
cmake version 4.0.3
CMake suite maintained and supported by Kitware (kitware.com/cmake).
1.11.1.git.kitware.jobserver-1
Executing workflow step 1 of 4: configure preset "dev"
CMake Warning (dev) at cmake/prelude.cmake:17 (if):
uninitialized variable 'CXX'
Call Stack (most recent call first):
CMakeLists.txt:3 (include)
This warning is for project developers. Use -Wno-dev to suppress it.
CMake Warning (dev) at cmake/WindowsToolchain/Windows.MSVC.toolchain.cmake:212 (set):
uninitialized variable 'CMAKE_C_FLAGS_INIT'
Call Stack (most recent call first):
C:/hostedtoolcache/windows/Python/3.13.3/x64/Lib/site-packages/cmake/data/share/cmake-4.0/Modules/CMakeDetermineSystem.cmake:146 (include)
CMakeLists.txt:5 (project)
This warning is for project developers. Use -Wno-dev to suppress it.
CMake Warning (dev) at cmake/WindowsToolchain/Windows.MSVC.toolchain.cmake:212 (set):
uninitialized variable 'CMAKE_CXX_FLAGS_INIT'
Call Stack (most recent call first):
C:/hostedtoolcache/windows/Python/3.13.3/x64/Lib/site-packages/cmake/data/share/cmake-4.0/Modules/CMakeDetermineSystem.cmake:146 (include)
CMakeLists.txt:5 (project)
This warning is for project developers. Use -Wno-dev to suppress it.
-- The CXX compiler identification is MSVC 19.43.34808.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files/Microsoft Visual Studio/2022/Enterprise/VC/Tools/MSVC/14.43.34808/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
CMake Warning (dev) at C:/hostedtoolcache/windows/Python/3.13.3/x64/Lib/site-packages/cmake/data/share/cmake-4.0/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):
C:/hostedtoolcache/windows/Python/3.13.3/x64/Lib/site-packages/cmake/data/share/cmake-4.0/Modules/CMakeDetermineCompilerSupport.cmake:113 (cmake_create_cxx_import_std)
C:/hostedtoolcache/windows/Python/3.13.3/x64/Lib/site-packages/cmake/data/share/cmake-4.0/Modules/CMakeTestCXXCompiler.cmake:83 (CMAKE_DETERMINE_COMPILER_SUPPORT)
CMakeLists.txt:5 (project)
This warning is for project developers. Use -Wno-dev to suppress it.
-- Detecting CXX compile features - done
-- CMAKE_CXX_COMPILER_IMPORT_STD=23
-- CMAKE_CXX_MODULE_STD=ON
-- ALGO_USE_MODULES=TRUE
-- CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES=
-- Performing Test COMPILER_HAS_DEPRECATED_ATTR
-- Performing Test COMPILER_HAS_DEPRECATED_ATTR - Failed
-- Performing Test COMPILER_HAS_DEPRECATED
-- Performing Test COMPILER_HAS_DEPRECATED - Success
-- Configuring done (6.4s)
CMake Warning:
Manually-specified variables were not used by the project:
BUILD_MCSS_DOCS
cmake-init-modules_DEVELOPER_MODE
-- Generating done (0.0s)
-- Build files have been written to: D:/a/cmake-init-modules/cmake-init-modules/build/dev
Executing workflow step 2 of 4: build preset "dev"
[1/17] Building CXX object CMakeFiles\Algo_verify_interface_header_sets.dir\Algo_verify_interface_header_sets\algo_export.h.cxx.obj
[2/17] Scanning D:\a\cmake-init-modules\cmake-init-modules\algo-interface.cppm for CXX dependencies
algo-interface.cppm
[3/17] Scanning "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.43.34808\modules\std.compat.ixx" for CXX dependencies
std.compat.ixx
[4/17] Scanning D:\a\cmake-init-modules\cmake-init-modules\example\main.cpp for CXX dependencies
[5/17] Scanning D:\a\cmake-init-modules\cmake-init-modules\algo-impl.cpp for CXX dependencies
[6/17] Scanning "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.43.34808\modules\std.ixx" for CXX dependencies
std.ixx
[7/17] Generating CXX dyndep file CMakeFiles\__cmake_cxx23.dir\CXX.dd
[8/17] Generating CXX dyndep file CMakeFiles\Algo.dir\CXX.dd
[9/17] Generating CXX dyndep file example\CMakeFiles\app.dir\CXX.dd
[10/17] Building CXX object CMakeFiles\__cmake_cxx23.dir\C_\Program_Files\Microsoft_Visual_Studio\2022\Enterprise\VC\Tools\MSVC\14.43.34808\modules\std.ixx.obj
std.ixx
[11/17] Building CXX object CMakeFiles\__cmake_cxx23.dir\C_\Program_Files\Microsoft_Visual_Studio\2022\Enterprise\VC\Tools\MSVC\14.43.34808\modules\std.compat.ixx.obj
std.compat.ixx
[12/17] Linking CXX static library __cmake_cxx23.lib
[13/17] Building CXX object CMakeFiles\Algo.dir\algo-interface.cppm.obj
algo-interface.cppm
D:\a\cmake-init-modules\cmake-init-modules\algo-interface.cppm(6): warning C5202: a global module fragment can only contain preprocessor directives
[14/17] Building CXX object example\CMakeFiles\app.dir\main.cpp.obj
[15/17] Building CXX object CMakeFiles\Algo.dir\algo-impl.cpp.obj
[16/17] Linking CXX shared library stagedir\bin\Algo.dll
[17/17] Linking CXX executable stagedir\bin\app.exe
Executing workflow step 3 of 4: test preset "dev"
Test project D:/a/cmake-init-modules/cmake-init-modules/build/dev
Start 1: app-tests
Start 2: install-to-stagedir
Start 3: find-package-test
1/3 Test #1: app-tests ........................ Passed 0.01 sec
2/3 Test #2: install-to-stagedir .............. Passed 0.02 sec
3/3 Test #3: find-package-test ................ Passed 5.11 sec
100% tests passed, 0 tests failed out of 3
Total Test time (real) = 5.12 sec
Executing workflow step 4 of 4: package preset "dev"
CPack: Create package using TGZ
CPack: Install projects
CPack: - Install project: my_package [Debug]
CPack: Create package
CPack: - package: D:/a/cmake-init-modules/cmake-init-modules/build/dev/my_package-0.2.0-win64.tar.gz generated.
I don’t know why you are pointing me to this, I have my llvm ```built from source`` with libc++ installed, I can use libc++ to cross compile to 6 platforms I just can’t use std lib modules
Either the build system is bugged, or my build system configuration is wrong.
My build system configuration can’t be wrong because I can use it to import std on WSL.
If my toolchain were buggy, than I wouldn’t have this issue on Android NDK and Emscripten as well.
Well, I read that and wanna say this:
I’m not doing anything exceptional. I’m just trying to build a simple hello world with import std but these combinations fail
CMake compiled from source + llvm compiled from source
CMake 4.0.3 + LLVM install by scoop
CMake 4.0.2 + Android NDK
CMake 4.0.2 + EMSDK
CMake 3.31.6 + Visual Studio Clang
CMake 3.31.7 + LLVM compiled from source
All use correct UUID’s of course, I can’t be at fault here, It is just not possible.
Before posting here I did these
I posted on discord
I created an issue on Gitlab
I tried using different build systems(xmake works)
Dude, you didn’t gave me any useful info at all, I can’t work with this, tell me that I have to point to libc++ config by setting a variable or smith like that, stuff I can try out
You just pass me test results and expect me to fix this problem.
I did, and by removing CMAKE_CXX_COMPILER and setting the path, like you asked
PS C:\Users\cakit\Desktop\std> $env:CXX = "clang++"
PS C:\Users\cakit\Desktop\std> cmake -G Ninja -S . -B build --fresh --trace-expand --trace-source=Clang-CXX-CXXImportStd.cmake
Put cmake in trace mode, but with variables expanded.
Put cmake in trace mode, but output only lines of a specified file. Multiple options are allowed.
-- The CXX compiler identification is Clang 21.0.0 with GNU-like command-line
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/dev/toolchains/llvm/bin/clang++.exe - skipped
-- Detecting CXX compile features
C:/Users/cakit/scoop/apps/cmake/current/share/cmake-4.0/Modules/Compiler/Clang-CXX-CXXImportStd.cmake(1): function(_cmake_cxx_import_std std variable )
CMake Warning (dev) at C:/Users/cakit/scoop/apps/cmake/current/share/cmake-4.0/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):
C:/Users/cakit/scoop/apps/cmake/current/share/cmake-4.0/Modules/CMakeDetermineCompilerSupport.cmake:113 (cmake_create_cxx_import_std)
C:/Users/cakit/scoop/apps/cmake/current/share/cmake-4.0/Modules/CMakeTestCXXCompiler.cmake:83 (CMAKE_DETERMINE_COMPILER_SUPPORT)
CMakeLists.txt:7 (project)
This warning is for project developers. Use -Wno-dev to suppress it.
C:/Users/cakit/scoop/apps/cmake/current/share/cmake-4.0/Modules/Compiler/Clang-CXX-CXXImportStd.cmake(2): if(CMAKE_CXX_STANDARD_LIBRARY STREQUAL libc++ )
C:/Users/cakit/scoop/apps/cmake/current/share/cmake-4.0/Modules/Compiler/Clang-CXX-CXXImportStd.cmake(4): elseif(CMAKE_CXX_STANDARD_LIBRARY STREQUAL libstdc++ )
C:/Users/cakit/scoop/apps/cmake/current/share/cmake-4.0/Modules/Compiler/Clang-CXX-CXXImportStd.cmake(6): else()
C:/Users/cakit/scoop/apps/cmake/current/share/cmake-4.0/Modules/Compiler/Clang-CXX-CXXImportStd.cmake(7): set(target_definition set(CMAKE_CXX23_COMPILER_IMPORT_STD_NOT_FOUND_MESSAGE "Only `libc++` and `libstdc++` are supported")
PARENT_SCOPE )
C:/Users/cakit/scoop/apps/cmake/current/share/cmake-4.0/Modules/Compiler/Clang-CXX-CXXImportStd.cmake(10): return()
C:/Users/cakit/scoop/apps/cmake/current/share/cmake-4.0/Modules/Compiler/Clang-CXX-CXXImportStd.cmake(1): function(_cmake_cxx_import_std std variable )
C:/Users/cakit/scoop/apps/cmake/current/share/cmake-4.0/Modules/Compiler/Clang-CXX-CXXImportStd.cmake(2): if(CMAKE_CXX_STANDARD_LIBRARY STREQUAL libc++ )
C:/Users/cakit/scoop/apps/cmake/current/share/cmake-4.0/Modules/Compiler/Clang-CXX-CXXImportStd.cmake(4): elseif(CMAKE_CXX_STANDARD_LIBRARY STREQUAL libstdc++ )
C:/Users/cakit/scoop/apps/cmake/current/share/cmake-4.0/Modules/Compiler/Clang-CXX-CXXImportStd.cmake(6): else()
C:/Users/cakit/scoop/apps/cmake/current/share/cmake-4.0/Modules/Compiler/Clang-CXX-CXXImportStd.cmake(7): set(target_definition set(CMAKE_CXX26_COMPILER_IMPORT_STD_NOT_FOUND_MESSAGE "Only `libc++` and `libstdc++` are supported")
PARENT_SCOPE )
C:/Users/cakit/scoop/apps/cmake/current/share/cmake-4.0/Modules/Compiler/Clang-CXX-CXXImportStd.cmake(10): return()
-- Detecting CXX compile features - done
-- Configuring done (1.9s)
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:
Only `libc++` and `libstdc++` are supported
-- Generating done (0.0s)
CMake Generate step failed. Build files cannot be regenerated correctly.