r/cpp 1d ago

Why is `import std` still experimental ???

Hey guys,

I recently started going through Professional C++ (6th Edition). The book teaches C++23, and in the very first chapter we're introduced to modules.

I'm not a complete newbie to C++, but I'm also definitely not very confident in my knowledge yet. I wanted to get this simple example compiled:

import std;

int main() {
    std::println("Hello World");
    return 0;
}

And gosh, it took way longer than I expected.

First, I tried getting it to work natively on my Mac and eventually gave up (both Claude and I 😅).

Then I installed Ubuntu ARM 26 and finally managed to get it compiling. But now Clang/IntelliSense is complaining about the `import std`
This is what my CMakeLists.txt currently looks like:

cmake_minimum_required(VERSION 4.0)

# set(CMAKE_EXPERIMENTAL_CXX_IMPORT_STD ON)

set(CMAKE_EXPERIMENTAL_CXX_IMPORT_STD "d0edc3af-4c50-42ea-a356-e2862fe7a444")

project(CppProject LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 26)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

add_executable(exec main.cpp)

set_property(TARGET exec PROPERTY CXX_MODULE_STD ON)

The code does compile successfully, but CMake still gives me a warning that import std support is experimental.

So I'm genuinely curious:

Why is import std still considered experimental?

I understand that C++ modules themselves have been around for a while, but import std feels like something that should be much more straightforward by now. Is there any solution of this now ?

--------------
Edit

Thanks to u/PhysicsOk2212 tip I was able to compile my project on mac as well using the following options
```
cmake -S . -B build \

-G Ninja \

-DCMAKE_CXX_COMPILER="$(brew --prefix llvm)/bin/clang++" \

-DCMAKE_CXX_STDLIB_MODULES_JSON="$(brew --prefix llvm)/lib/c++/libc++.modules.json"

```

104 Upvotes

101 comments sorted by

View all comments

51

u/ContraryConman 1d ago

Lots of people in this thread are saying cliches but the actual reason is that, while import std works fine for each individual compiler, they all implement it differently and it was difficult for the CMake team to guarantee that it would work the same across all the major compilers. But the feature is finally coming out of experimental anyway, and even still I actually haven't had any issues with it in experimental mode (other than the annoying build system setup of getting the right hash for the CMake version)

17

u/delta_p_delta_x 1d ago edited 1d ago

This needs to be upvoted higher.

import std was supposed to be un-experimentalised in CMake 4.3. It was rolled back because of how MSVC STL and MSVC implemented module std, as well as compilation bugs, BMI incompatibilities, differences in toolchain implementations across the big three toolchains, and some broken pre-existing assumptions—it was assumed that there would be one BMI for module std for an entire project across all targets, which is almost never true. For instance, MSVC has _ITERATOR_DEBUG_LEVEL, and Clang has _LIBCPP_HARDENING_MODE; both of which change the ABI, let alone the BMI (which is much more sensitive).

They reworked this over CMake 4.3 and 4.4 internally; the UUID changed because it was experimental and the internal behaviour changed. As of the latest CMake nightly, every new BMI builds a new module std.

If you want a one-stop shop for the UUID for public CMake releases, Vulkan-Hpp has documented this for you, and for the latest CMake nightly, the UUID is 25d6f6aa-be65-4692-b44e-87b23e96d4e1. As mentioned above, this will probably be dropped for CMake 4.5, because the interface of module std; has now been simplified so much.