# Import std - cmake 3.30 - "config mismatch" error

**URL:** https://discourse.cmake.org/t/import-std-cmake-3-30-config-mismatch-error/12908
**Category:** Code
**Tags:** os:linux, gen:ninja
**Created:** [November 7, 2024, 6:23am UTC](https://discourse.cmake.org/t/import-std-cmake-3-30-config-mismatch-error/12908 "2024-11-07T06:23:17Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Kelarov](https://discourse.cmake.org/user_avatar/discourse.cmake.org/kelarov/32/4927_2.png) [@Kelarov](https://discourse.cmake.org/u/Kelarov)
#### Post date: [November 7, 2024, 6:23am UTC](https://discourse.cmake.org/t/import-std-cmake-3-30-config-mismatch-error/12908/1 "2024-11-07T06:23:17Z")

</div>

Hi all.  
I am trying to apply what the [import std in CMake 3.30](https://www.kitware.com/import-std-in-cmake-3-30/) post does to use in a project, but am facing errors.

## My setup:

```sh
CMakeLists.txt
CMakePresets.json
src/CMakeLists.txt
src/kk-intro.cppm
src/kk-intro.cc
src/main.cc

```

## `CMakeLists.txt`:

```cmake
cmake_minimum_required(VERSION 3.30)

set(CMAKE_EXPERIMENTAL_CXX_IMPORT_STD
  "0e5b6991-d74f-4b3d-a41c-cf096e0b2508")

project(kk LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

add_subdirectory(src)

```

## `CMakePresets.json` (simplified)

```json
{
  "version": 8,
  "configurePresets": [
    {
      "name": "linux-base",
      "hidden": true,
      "generator": "Ninja",
      "binaryDir": "${sourceDir}/build/${presetName}",
      "installDir": "${sourceDir}/install/${presetName}",
      "cacheVariables": {
        "CMAKE_CXX_COMPILER": "clang++",
        "CMAKE_CXX_FLAGS": "-stdlib=libc++",
        "CMAKE_EXE_LINKER_FLAGS": "-fuse-ld=lld -stdlib=libc++",
      },
      "condition": {
        "type": "equals",
        "lhs": "${hostSystemName}",
        "rhs": "Linux"
      }
    },
    {
      "name": "lnx-debug-C",
      "inherits": "linux-base",
      "architecture": {
        "value": "x64",
        "strategy": "external"
      },
      "cacheVariables": {
        "CMAKE_BUILD_TYPE": "Debug"
      }
    },
    {
      "name": "lnx-release-C",
      "inherits": "linux-base",
      "architecture": {
        "value": "x64",
        "strategy": "external"
      },
      "cacheVariables": {
        "CMAKE_BUILD_TYPE": "Release"
      }
    }
  ],
  "buildPresets": [
    {
      "name": "lnx-release-B",
      "displayName": "LnxRelB",
      "configurePreset": "lnx-release-C"
    },
    {
      "name": "lnx-debug-B",
      "displayName": "LnxDbgB",
      "configurePreset": "lnx-debug-C"
    }
  ],
}

```

## `src/CMakeLists.txt`

```cmake
set(CMAKE_CXX_MODULE_STD 1)

add_library(kk STATIC)
target_sources(kk
  PRIVATE kk-intro.cc
  PUBLIC
    FILE_SET CXX_MODULES 
    FILES kk-intro.cppm)

target_compile_features(kk
  PRIVATE cxx_std_23
  INTERFACE cxx_std_23)

add_executable(main)
target_sources(main
  PRIVATE main.cc)
target_link_libraries(main
  PRIVATE kk)

```

## The module and `main.cc` files (just for demo purposes)

```cpp
// kk-intro.cppm
export module kk;
import std;

export namespace kk {
constexpr std::string module_name{"kk"};
void print_hello_world();
} 
// kk-intro.cc
module kk;

namespace kk {
void print_hello_world() { std::println("Hello, World!"); }
}

// src/main.cc
import kk;
import std;

int main() {
  kk::print_hello_world();
  std::println("Setting up {}!", kk::module_name);
}

```

# Compiler- and lib-wise

- I have `clang++` installed on `$HOME/tools/llvm19.1.3` - this directory in is my `$PATH`.
- I don’t know whether this is necessary, but I added `export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$HOME/tools/llvm19.1.3/lib/x86_64-unknown-linux-gnu/` to my `~/.bashrc`.

## Extras

Now, some of my rationale behind some of the code:

- I thought that adding `std_cxx_23` to both `PRIVATE` and `INTERFACE` in `target_compile_features(kk ...` would allow me to use `import std;` on `main.cc`. At least this was the idea. I’ve tried not doing that, but that didn’t solve the problem.
- I have the feeling the problem has to do with compiler and link flags that I’m not properly using.

The error that seems to blow up everything is:

```sh
cmake --workflow lnx-config-build-dbg
Executing workflow step 1 of 2: configure preset "lnx-debug-C"

Preset CMake variables:

  CMAKE_BUILD_TYPE="Debug"
  CMAKE_CXX_COMPILER="clang++"
  CMAKE_CXX_FLAGS="-stdlib=libc++"
  CMAKE_EXE_LINKER_FLAGS="-fuse-ld=lld -stdlib=libc++"
  CMAKE_INSTALL_PREFIX:PATH="/home/elmago/cpp/install/lnx-debug-C"

-- The CXX compiler identification is Clang 19.1.3
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /home/elmago/tools/llvm19.1.3/bin/clang++ - skipped
-- Detecting CXX compile features
CMake Warning (dev) at /home/elmago/.local/share/cmake-3.31/Modules/Compiler/CMakeCommonCompilerMacros.cmake:248 (cmake_language):
  CMakes 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):
  /home/elmago/.local/share/cmake-3.31/Modules/CMakeDetermineCompilerSupport.cmake:113 (cmake_create_cxx_import_std)
  /home/elmago/.local/share/cmake-3.31/Modules/CMakeTestCXXCompiler.cmake:83 (CMAKE_DETERMINE_COMPILER_SUPPORT)
  CMakeLists.txt:9 (project)
This warning is for project developers. Use -Wno-dev to suppress it.

-- Detecting CXX compile features - done
-- Configuring done (0.2s)
-- Generating done (0.0s)
-- Build files have been written to: /home/elmago/cpp/build/lnx-debug-C

Executing workflow step 2 of 2: build preset "lnx-debug-B"

[10/16] Building CXX object src/CMakeFiles/kk.dir/kk-intro.cppm.o
FAILED: src/CMakeFiles/kk.dir/kk-intro.cppm.o src/CMakeFiles/kk.dir/kk.pcm
/home/elmago/tools/llvm19.1.3/bin/clang++ -D_LIBCPP_REMOVE_TRANSITIVE_INCLUDES -stdlib=libc++ -g -std=c++23 -MD -MT src/CMakeFiles/kk.dir/kk-intro.cppm.o -MF src/CMakeFiles/kk.dir/kk-intro.cppm.o.d @src/CMakeFiles/kk.dir/kk-intro.cppm.o.modmap -o src/CMakeFiles/kk.dir/kk-intro.cppm.o -c /home/elmago/cpp/src/kk-intro.cppm
error: GNU extensions was enabled in PCH file but is currently disabled
error: module file CMakeFiles/__cmake_cxx23.dir/std.pcm cannot be loaded due to a configuration mismatch with the current compilation [-Wmodule-file-config-mismatch]
/home/elmago/cpp/src/kk-intro.cppm:5:11: error: use of undeclared identifier 'std'
    5 | constexpr std::string module_name{"kk"};
      | ^
3 errors generated.
[11/16] Building CXX object CMakeFiles/__cmake_cxx23.di...mago/tools/llvm19.1.3/share/libc++/v1/std.compat.cppm.
ninja: build stopped: subcommand failed.

```

- That mention of `GNU extensions`, PCH, etc. Why? Where?
- Now, `std.pcm` relates to `CMakeFiles/__cmake_cxx23.dir/std.pcm` but `std.compat.pcm` relates to the `LD_LIBRARY_PATH` that I set. Weird, and I don’t know how to actually interpret that.

I appreciate any help in advance.

---

<div class="post-metadata">

### Author: ![ClausKlein](https://discourse.cmake.org/user_avatar/discourse.cmake.org/clausklein/32/352_2.png) [@ClausKlein](https://discourse.cmake.org/u/ClausKlein)
#### Post date: [November 7, 2024, 7:59am UTC](https://discourse.cmake.org/t/import-std-cmake-3-30-config-mismatch-error/12908/2 "2024-11-07T07:59:03Z")

</div>

> [@Kelarov](#):
>
> `set(CMAKE_CXX_EXTENSIONS OFF)`

AFAIK you should use:  
_set(CMAKE\_CXX\_EXTENSIONS ON)_

---

<div class="post-metadata">

### Author: ![Kelarov](https://discourse.cmake.org/user_avatar/discourse.cmake.org/kelarov/32/4927_2.png) [@Kelarov](https://discourse.cmake.org/u/Kelarov)
#### Post date: [November 7, 2024, 8:32am UTC](https://discourse.cmake.org/t/import-std-cmake-3-30-config-mismatch-error/12908/4 "2024-11-07T08:32:55Z")

</div>

You have to got to be kidding me haha. I would never suspect that. I didn’t see any mention of this extension thingy in the docs. I don’t know. Maybe I’m just too stupid.

Anyway. That line, indeed, breaks things.  
THANK YOU SO MUCH FOR POINTING THAT OUT.

Cheers.

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [February 20, 2026, 5:48am UTC](https://discourse.cmake.org/t/import-std-cmake-3-30-config-mismatch-error/12908/5 "2026-02-20T05:48:14Z")

</div>

See this issue for tracking CMake fixing this properly: [https://gitlab.kitware.com/cmake/cmake/-/issues/27597](https://gitlab.kitware.com/cmake/cmake/-/issues/27597).
