# Import std in clang with custom stdlibc++

**URL:** https://discourse.cmake.org/t/import-std-in-clang-with-custom-stdlibc/14042
**Category:** Usage
**Tags:** comp:gcc, comp:clang
**Created:** [May 4, 2025, 2:16pm UTC](https://discourse.cmake.org/t/import-std-in-clang-with-custom-stdlibc/14042 "2025-05-04T14:16:31Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![krzysztofkortas](https://discourse.cmake.org/user_avatar/discourse.cmake.org/krzysztofkortas/32/5547_2.png) [@krzysztofkortas](https://discourse.cmake.org/u/krzysztofkortas)
#### Post date: [May 4, 2025, 2:16pm UTC](https://discourse.cmake.org/t/import-std-in-clang-with-custom-stdlibc/14042/1 "2025-05-04T14:16:31Z")

</div>

Merge request [10727](https://gitlab.kitware.com/cmake/cmake/-/merge_requests/10727) added support for `import std` using `clang` and `stdlibc++`. I use `clang` with a custom `gcc` installation passed through a flag `--gcc-install-dir` via `CMAKE_CXX_FLAGS`.

In the `Clang-CXX-CXXImportStd.cmake` file, there is the following call:

```auto
execute_process(
    COMMAND
      "${CMAKE_CXX_COMPILER}"
      ${CMAKE_CXX_COMPILER_ID_ARG1}
      "-print-file-name=${_clang_modules_json_impl}.modules.json"
    OUTPUT_VARIABLE _clang_libcxx_modules_json_file
    ERROR_VARIABLE _clang_libcxx_modules_json_file_err
    RESULT_VARIABLE _clang_libcxx_modules_json_file_res
    OUTPUT_STRIP_TRAILING_WHITESPACE
    ERROR_STRIP_TRAILING_WHITESPACE)

```

This call ignores `CMAKE_CXX_FLAGS` so it uses the `gcc12` installed on my system and `libstdc++.modules.json` isn’t found. Is this a bug or can I somehow pass `--gcc-install-dir` to this call or specify a path to `libstdc++.modules.json` by hand?

---

<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: [May 5, 2025, 5:42am UTC](https://discourse.cmake.org/t/import-std-in-clang-with-custom-stdlibc/14042/2 "2025-05-05T05:42:29Z")

</div>

Hmm. Does adding `${CMAKE_CXX_FLAGS}` to the argument list fix it?

---

<div class="post-metadata">

### Author: ![krzysztofkortas](https://discourse.cmake.org/user_avatar/discourse.cmake.org/krzysztofkortas/32/5547_2.png) [@krzysztofkortas](https://discourse.cmake.org/u/krzysztofkortas)
#### Post date: [May 5, 2025, 9:16pm UTC](https://discourse.cmake.org/t/import-std-in-clang-with-custom-stdlibc/14042/3 "2025-05-05T21:16:41Z")

</div>

Yes, adding `CMAKE_CXX_FLAGS` fixes it.  
My `CMAKE_CXX_FLAGS` looks like this: `set(CMAKE_CXX_FLAGS "--gcc-install-dir=/usr/local/lib/gcc/x86_64-linux-gnu/16.0.0 --stdlib=libstdc++")` so that’s what I did to get it to work:

```auto
separate_arguments(_cxx_flags_list NATIVE_COMMAND "${CMAKE_CXX_FLAGS}")

execute_process(
  COMMAND
    "${CMAKE_CXX_COMPILER}"
    ${CMAKE_CXX_COMPILER_ID_ARG1}
    ${_cxx_flags_list}
    "-print-file-name=${_clang_modules_json_impl}.modules.json"
  OUTPUT_VARIABLE _clang_libcxx_modules_json_file
  ERROR_VARIABLE _clang_libcxx_modules_json_file_err
  RESULT_VARIABLE _clang_libcxx_modules_json_file_res
  OUTPUT_STRIP_TRAILING_WHITESPACE
  ERROR_STRIP_TRAILING_WHITESPACE)

```

I saw `CMAKE_CXX_COMPILER_ID_FLAGS_LIST` used in another place, but it was empty in my context.

---

<div class="post-metadata">

### Author: ![krzysztofkortas](https://discourse.cmake.org/user_avatar/discourse.cmake.org/krzysztofkortas/32/5547_2.png) [@krzysztofkortas](https://discourse.cmake.org/u/krzysztofkortas)
#### Post date: [June 5, 2025, 7:28pm UTC](https://discourse.cmake.org/t/import-std-in-clang-with-custom-stdlibc/14042/4 "2025-06-05T19:28:42Z")

</div>

Are you going to fix it, or is it an unsupported configuration?
