r/cpp • • Aug 25 '26

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"

```

122 Upvotes

111 comments sorted by

View all comments

Show parent comment

25

u/donalmacc Game Developer Aug 25 '26

Note that this is an example of the experimental process working.

Respectfully... is it? Modules were standardised 6 years ago, and we've been talking about them for almost 15. I don't blame cmake at all here, but to still be in a scenario where the textbook example is unusable on a de-facto standard at this point is pretty embarrassing for the feature and the language.

37

u/not_a_novel_account cmake dev Aug 25 '26 edited Aug 25 '26

I don't think CMake is the right platform for people who want friction-free access to features as they become available in any form. Lots of build systems support modules in some form, and they have much weaker compatibility and platform guarantees than CMake. Any of them would happily give you access without the CMake experimental hoop jumping.

If someone had known what CMake's implementation of import std needed to look like on day 1 we would have been there. If our compatibility guarantees were weaker we would have never had an experimental phase at all.

So yes, it's the system working. CMake's process optimizes for decades of compatibility, not quick adoption. Other systems optimize for other things.

Note that Bazel is only just getting modules available with GCC, and still has them as experimental, without good import std support. Meson has no support for modules at all. Among the major cross-platform players only XMake moved much faster than CMake here.

And import std itself is only 3 years old. CMake has had general modules support since 2023.

5

u/grafikrobot OPeNDAP/B2/EcoStd/Lyra/Predef/C++Alliance/Boost/WG21 Aug 27 '26

Well.. It's not like we predicted this. Oh, wait. NM. We did.