# Cannot build modules using cmake and clang-18: "compiler does not provide a way to discover the import graph dependencies"

**URL:** <https://discourse.cmake.org/t/cannot-build-modules-using-cmake-and-clang-18-compiler-does-not-provide-a-way-to-discover-the-import-graph-dependencies/9757>\
**Category:** Code\
**Created:** [January 2, 2024, 11:04am UTC](https://discourse.cmake.org/t/cannot-build-modules-using-cmake-and-clang-18-compiler-does-not-provide-a-way-to-discover-the-import-graph-dependencies/9757 "2024-01-02T11:04:59Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![johnworchester](https://discourse.cmake.org/user_avatar/discourse.cmake.org/johnworchester/32/4132_2.png) [@johnworchester](https://discourse.cmake.org/u/johnworchester)\
**Post date:** [January 2, 2024, 11:04am UTC](https://discourse.cmake.org/t/cannot-build-modules-using-cmake-and-clang-18-compiler-does-not-provide-a-way-to-discover-the-import-graph-dependencies/9757/1 "2024-01-02T11:04:59Z")

</div>

Since the support is now stable ([https://www.kitware.com/import-cmake-the-experiment-is-over/](https://www.kitware.com/import-cmake-the-experiment-is-over/)), I tried out C++ modules using cmake and clang 18.

However, compiling the source gave me:

```auto
The target named "<target>" has C++ sources that may use modules, but the
compiler does not provide a way to discover the import graph dependencies.
See the cmake-cxxmodules(7) manual for details. Use the
CMAKE_CXX_SCAN_FOR_MODULES variable to enable or disable scanning.

```

clang --version:

```auto
Debian clang version 18.0.0 (++20240101112328+703e83611cd8-1~exp1~20240101112345.435)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

```

cmake --version:

```auto
cmake version 3.28.1    
CMake suite maintained and supported by Kitware (kitware.com/cmake).

```

CMakeLists.txt:

```auto
add_library(lib STATIC)
target_sources(lib
  PUBLIC
  FILE_SET CXX_MODULES FILES
  file.ccm
)

```

Any pointers?

---

<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:** [January 2, 2024, 1:04pm UTC](https://discourse.cmake.org/t/cannot-build-modules-using-cmake-and-clang-18-compiler-does-not-provide-a-way-to-discover-the-import-graph-dependencies/9757/2 "2024-01-02T13:04:31Z")

</div>

Do you have a `clang-scan-deps` binary around?

---

<div class="post-metadata">

**Author:** ![johnworchester](https://discourse.cmake.org/user_avatar/discourse.cmake.org/johnworchester/32/4132_2.png) [@johnworchester](https://discourse.cmake.org/u/johnworchester)\
**Post date:** [January 2, 2024, 1:43pm UTC](https://discourse.cmake.org/t/cannot-build-modules-using-cmake-and-clang-18-compiler-does-not-provide-a-way-to-discover-the-import-graph-dependencies/9757/3 "2024-01-02T13:43:50Z")

</div>

In fact I did not, but even if I install it, that makes no difference.  
I have a debian installation running, I installed cmake via the script from the download section and clang-18 from the official LLVM repo.

```auto
$ clang-scan-deps --version
clang-scan-deps
Debian LLVM version 18.0.0
  Optimized build.

```

But thanks for the effort.

---

<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:** [January 2, 2024, 1:45pm UTC](https://discourse.cmake.org/t/cannot-build-modules-using-cmake-and-clang-18-compiler-does-not-provide-a-way-to-discover-the-import-graph-dependencies/9757/4 "2024-01-02T13:45:50Z")

</div>

Hmm. That is odd. Debian stable or testing? I’ll try it out in a container here.

---

<div class="post-metadata">

**Author:** ![johnworchester](https://discourse.cmake.org/user_avatar/discourse.cmake.org/johnworchester/32/4132_2.png) [@johnworchester](https://discourse.cmake.org/u/johnworchester)\
**Post date:** [January 2, 2024, 1:49pm UTC](https://discourse.cmake.org/t/cannot-build-modules-using-cmake-and-clang-18-compiler-does-not-provide-a-way-to-discover-the-import-graph-dependencies/9757/5 "2024-01-02T13:49:41Z")

</div>

standard debian from WSL

```auto
$ lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description: Debian GNU/Linux 12 (bookworm)
Release: 12
Codename: bookworm
$ uname -a
Linux NAME 5.15.133.1-microsoft-standard-WSL2 #1 SMP Thu Oct 5 21:02:42 UTC 2023 x86_64 GNU/Linux
$ ls -lsa /usr/bin/ | grep clang
0 lrwxrwxrwx 1 root root 24 Jul 27 13:38 clang -> ../lib/llvm-18/bin/clang
0 lrwxrwxrwx 1 root root 26 Jul 27 13:38 clang++ -> ../lib/llvm-18/bin/clang++
0 lrwxrwxrwx 1 root root 26 Feb 17 2023 clang++-14 -> ../lib/llvm-14/bin/clang++
0 lrwxrwxrwx 1 root root 24 Feb 17 2023 clang-14 -> ../lib/llvm-14/bin/clang
0 lrwxrwxrwx 1 root root 26 Jan 1 12:23 clang++-18 -> ../lib/llvm-18/bin/clang++
0 lrwxrwxrwx 1 root root 24 Jan 1 12:23 clang-18 -> ../lib/llvm-18/bin/clang
0 lrwxrwxrwx 1 root root 43 Jan 1 12:23 clang-apply-replacements-18 -> ../lib/llvm-18/bin/clang-apply-replacements
0 lrwxrwxrwx 1 root root 41 Jan 1 12:23 clang-change-namespace-18 -> ../lib/llvm-18/bin/clang-change-namespace
0 lrwxrwxrwx 1 root root 30 Jan 1 12:23 clang-check-18 -> ../lib/llvm-18/bin/clang-check
0 lrwxrwxrwx 1 root root 27 Jan 1 12:23 clang-cl-18 -> ../lib/llvm-18/bin/clang-cl
0 lrwxrwxrwx 1 root root 28 Feb 17 2023 clang-cpp-14 -> ../lib/llvm-14/bin/clang-cpp
0 lrwxrwxrwx 1 root root 28 Jan 1 12:23 clang-cpp-18 -> ../lib/llvm-18/bin/clang-cpp
0 lrwxrwxrwx 1 root root 25 Dec 8 09:59 clangd-17 -> ../lib/llvm-17/bin/clangd
0 lrwxrwxrwx 1 root root 28 Jan 1 12:23 clang-doc-18 -> ../lib/llvm-18/bin/clang-doc
0 lrwxrwxrwx 1 root root 39 Jan 1 12:23 clang-extdef-mapping-18 -> ../lib/llvm-18/bin/clang-extdef-mapping
0 lrwxrwxrwx 1 root root 15 Jul 27 13:38 clang-format -> clang-format-18
0 lrwxrwxrwx 1 root root 31 Jan 1 12:23 clang-format-18 -> ../lib/llvm-18/bin/clang-format
0 lrwxrwxrwx 1 root root 20 Jul 27 13:38 clang-format-diff -> clang-format-diff-18
8 -rwxr-xr-x 1 root root 6273 Jan 1 12:23 clang-format-diff-18
0 lrwxrwxrwx 1 root root 40 Jan 1 12:23 clang-include-cleaner-18 -> ../lib/llvm-18/bin/clang-include-cleaner
0 lrwxrwxrwx 1 root root 38 Jan 1 12:23 clang-include-fixer-18 -> ../lib/llvm-18/bin/clang-include-fixer
0 lrwxrwxrwx 1 root root 39 Jan 1 12:23 clang-linker-wrapper-18 -> ../lib/llvm-18/bin/clang-linker-wrapper
0 lrwxrwxrwx 1 root root 29 Jan 1 12:23 clang-move-18 -> ../lib/llvm-18/bin/clang-move
0 lrwxrwxrwx 1 root root 40 Jan 1 12:23 clang-offload-bundler-18 -> ../lib/llvm-18/bin/clang-offload-bundler
0 lrwxrwxrwx 1 root root 41 Jan 1 12:23 clang-offload-packager-18 -> ../lib/llvm-18/bin/clang-offload-packager
0 lrwxrwxrwx 1 root root 31 Jan 1 12:23 clang-pseudo-18 -> ../lib/llvm-18/bin/clang-pseudo
0 lrwxrwxrwx 1 root root 30 Jan 1 12:23 clang-query-18 -> ../lib/llvm-18/bin/clang-query
0 lrwxrwxrwx 1 root root 33 Jan 1 12:23 clang-refactor-18 -> ../lib/llvm-18/bin/clang-refactor
0 lrwxrwxrwx 1 root root 31 Jan 1 12:23 clang-rename-18 -> ../lib/llvm-18/bin/clang-rename
0 lrwxrwxrwx 1 root root 39 Jan 1 12:23 clang-reorder-fields-18 -> ../lib/llvm-18/bin/clang-reorder-fields
0 lrwxrwxrwx 1 root root 29 Jan 1 12:23 clang-repl-18 -> ../lib/llvm-18/bin/clang-repl
0 lrwxrwxrwx 1 root root 27 Jan 2 14:34 clang-scan-deps -> /usr/bin/clang-scan-deps-18
0 lrwxrwxrwx 1 root root 34 Jan 1 12:23 clang-scan-deps-18 -> ../lib/llvm-18/bin/clang-scan-deps
0 lrwxrwxrwx 1 root root 31 Jan 1 12:23 clang-tblgen-18 -> ../lib/llvm-18/bin/clang-tblgen
0 lrwxrwxrwx 1 root root 19 Jul 27 13:38 git-clang-format -> git-clang-format-18
0 lrwxrwxrwx 1 root root 35 Jan 1 12:23 git-clang-format-18 -> ../lib/llvm-18/bin/git-clang-format
0 lrwxrwxrwx 1 root root 48 Jan 1 12:23 hwasan_symbolize-18 -> ../lib/llvm-18/lib/clang/18/bin/hwasan_symbolize
0 lrwxrwxrwx 1 root root 43 Jan 1 12:23 scan-build-18 -> ../share/clang/scan-build-18/bin/scan-build
0 lrwxrwxrwx 1 root root 41 Jan 1 12:23 scan-view-18 -> ../share/clang/scan-view-18/bin/scan-view

```

---

<div class="post-metadata">

**Author:** ![johnworchester](https://discourse.cmake.org/user_avatar/discourse.cmake.org/johnworchester/32/4132_2.png) [@johnworchester](https://discourse.cmake.org/u/johnworchester)\
**Post date:** [January 2, 2024, 2:26pm UTC](https://discourse.cmake.org/t/cannot-build-modules-using-cmake-and-clang-18-compiler-does-not-provide-a-way-to-discover-the-import-graph-dependencies/9757/6 "2024-01-02T14:26:40Z")

</div>

complete minimal example(same environment):

```auto
cmake_minimum_required(VERSION 3.28)
project(PACtrl LANGUAGES CXX)

add_library(test STATIC)
target_sources(test
  PUBLIC
  FILE_SET CXX_MODULES FILES
  test.ccm
)
set_property(TARGET test PROPERTY CXX_STANDARD 20)
set_property(TARGET test PROPERTY CXX_STANDARD_REQUIRED ON)
set_property(TARGET test PROPERTY CXX_EXTENSIONS OFF)

```

```auto
module;

export module test;

namespace test {
    int i(void)
    {
        return 1;
    }
}

```

```auto
$ cmake . build -GNinja
CMake Warning:
  Ignoring extra path from command line:

   "build"

-- Configuring done (0.0s)
CMake Error in CMakeLists.txt:
  The target named "test" has C++ sources that may use modules, but the
  compiler does not provide a way to discover the import graph dependencies.
  See the cmake-cxxmodules(7) manual for details. Use the
  CMAKE_CXX_SCAN_FOR_MODULES variable to enable or disable scanning.

-- Generating done (0.0s)
CMake Generate step failed. Build files cannot be regenerated correctly.

```

---

<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:** [January 2, 2024, 2:39pm UTC](https://discourse.cmake.org/t/cannot-build-modules-using-cmake-and-clang-18-compiler-does-not-provide-a-way-to-discover-the-import-graph-dependencies/9757/7 "2024-01-02T14:39:15Z")

</div>

CMake’s test suite ran fine:

```commands
$ apt install clang-tools-18
$ CC=clang-18 CXX=clang++-18 ../cmake-3.28.1-linux-x86_64/bin/cmake -GNinja ../src -DCMake_TEST_HOST_CMAKE=1 -DCMake_TEST_MODULE_COMPILATION=named,compile_commands,collation,partitions,internal_partitions,export_bmi,install_bmi,shared,bmionly
$ ninja
$ CC=clang-18 CXX=clang++-18 ../cmake-3.28.1-linux-x86_64/bin/ctest -R CXXModules

```

---

<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:** [January 2, 2024, 2:39pm UTC](https://discourse.cmake.org/t/cannot-build-modules-using-cmake-and-clang-18-compiler-does-not-provide-a-way-to-discover-the-import-graph-dependencies/9757/8 "2024-01-02T14:39:42Z")

</div>

Are you sure CMake is trying to use Clang and not GCC here?

---

<div class="post-metadata">

**Author:** ![johnworchester](https://discourse.cmake.org/user_avatar/discourse.cmake.org/johnworchester/32/4132_2.png) [@johnworchester](https://discourse.cmake.org/u/johnworchester)\
**Post date:** [January 2, 2024, 3:22pm UTC](https://discourse.cmake.org/t/cannot-build-modules-using-cmake-and-clang-18-compiler-does-not-provide-a-way-to-discover-the-import-graph-dependencies/9757/9 "2024-01-02T15:22:51Z")

</div>

Thanks, that was the issue. Somehow, GCC and clang got messed up.

---

<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:** [January 2, 2024, 4:02pm UTC](https://discourse.cmake.org/t/cannot-build-modules-using-cmake-and-clang-18-compiler-does-not-provide-a-way-to-discover-the-import-graph-dependencies/9757/10 "2024-01-02T16:02:02Z")

</div>

CMake defaults to searching for `cc` and `c++` which are (generally) GCC on Linux distros. If that doesn’t exist, GCC is searched for first.
