# Module not found error on 3.28

**URL:** <https://discourse.cmake.org/t/module-not-found-error-on-3-28/9507>\
**Category:** Code\
**Tags:** os:linux, gen:ninja\
**Created:** [November 26, 2023, 6:29am UTC](https://discourse.cmake.org/t/module-not-found-error-on-3-28/9507 "2023-11-26T06:29:15Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![nicobuzeta](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/n/f1d935/32.png) [@nicobuzeta](https://discourse.cmake.org/u/nicobuzeta)\
**Post date:** [November 26, 2023, 6:29am UTC](https://discourse.cmake.org/t/module-not-found-error-on-3-28/9507/1 "2023-11-26T06:29:15Z")

</div>

Hello, I’m trying to integrate the new modules functionality into a project. I’m currently having issues with the module not being found when I import it.

I’ve added this to my CMakeLists:

```auto
file(GLOB_RECURSE TEST_MODULE_FILES
    src/unit_tests/*.cppm
)

# print test_module_files
message("Test module files: ${TEST_MODULE_FILES}")

add_library(tests_modules)

target_sources(tests_modules PUBLIC
FILE_SET CXX_MODULES
FILES ${TEST_MODULE_FILES}
)

add_executable(tests ${UNIT_TESTING_FILES})
target_link_libraries(tests Catch2::Catch2WithMain core tests_modules)

```

In test.cppm I’m doing:

```auto
export module foo;

```

And in another file I have the import. However on build I get:  
…/src/unit\_tests/core\_server/internal/evaluation/evaluation\_algorithm/common.cpp:1:8: fatal error: module ‘foo’ not found  
import foo;

I’m using conan so I have a build directory /build/Debug/, could this be causing this? I’ve run the basic example with foo.cxx in a different directory and that one works fine.

Any help would be appreciated.

---

<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:** [November 26, 2023, 11:51am UTC](https://discourse.cmake.org/t/module-not-found-error-on-3-28/9507/2 "2023-11-26T11:51:12Z")

</div>

You should set your minimum CMake version to 3.28. Sources that are not in a `FILE_SET TYPE CXX_MODULES` cannot use modules (by default) if [`CMP0155`](https://cmake.org/cmake/help/latest/policy/CMP0155.html) is `OLD`. You can also use [`CMAKE_CXX_SCAN_FOR_MODULES`](https://cmake.org/cmake/help/latest/variable/CMAKE_CXX_SCAN_FOR_MODULES.html)

---

<div class="post-metadata">

**Author:** ![nicobuzeta](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/n/f1d935/32.png) [@nicobuzeta](https://discourse.cmake.org/u/nicobuzeta)\
**Post date:** [November 26, 2023, 2:06pm UTC](https://discourse.cmake.org/t/module-not-found-error-on-3-28/9507/3 "2023-11-26T14:06:09Z")

</div>

I’ve set:  
cmake\_minimum\_required(VERSION 3.28 FATAL\_ERROR)  
set(CMP0155 NEW)  
set(CMAKE\_CXX\_SCAN\_FOR\_MODULES ON)

I’ve also confirmed that the file with the export foo is contained inside of TEST\_MODULE\_FILES, so that file should have FILE\_SET CXX\_MODULES.

However I am still getting the same error. That said, I was going through the build directory and foo.pcm is being built. I can also see that the module is being picked up by tests (build/Debug/CMakeFiles/tests.dir):

```auto
...
	"language" : "CXX",
	"linked-target-dirs" : 
	[
		"/home/nicobuzeta/Documents/CORE_Project/CORE/build/Debug/CMakeFiles/tests_modules.dir"
	],
	"module-dir" : "/home/nicobuzeta/Documents/CORE_Project/CORE/build/Debug/CMakeFiles/tests.dir"

```

and

```auto
{
	"modules" : {},
	"references" : 
	{
		"foo" : 
		{
			"lookup-method" : "by-name",
			"path" : "CMakeFiles/tests_modules.dir/foo.pcm"
		}
	},
	"usages" : {}
}

```

In the tests\_modules.dir, I can also see that it is suppose to provide the module:

```auto
{
	"modules" : 
	{
		"foo" : 
		{
			"bmi" : "/home/nicobuzeta/Documents/CORE_Project/CORE/build/Debug/CMakeFiles/tests_modules.dir/foo.pcm",
			"is-private" : false
		}
	},
	"references" : 
	{
		"foo" : 
		{
			"lookup-method" : "by-name",
			"path" : "CMakeFiles/tests_modules.dir/foo.pcm"
		}
	},
	"usages" : {}
}

```

In the common.cpp.o.modmap I also have:

`-fmodule-file=foo=CMakeFiles/tests_modules.dir/foo.pcm`

However I still get:

```auto
FAILED: CMakeFiles/tests.dir/src/unit_tests/core_server/internal/evaluation/evaluation_algorithm/common.cpp.o
/usr/bin/clang++ -DCORE_DEBUG -DSODIUM_STATIC -DZMQ_STATIC -I/home/nicobuzeta/Documents/CORE_Project/CORE/src -isystem /home/nicobuzeta/.conan2/p/b/catchf35de5ff3cba0/p/include -isystem /home/nicobuzeta/.conan2/p/b/antlr5086bea15e1a6/p/include -isystem /home/nicobuzeta/.conan2/p/b/antlr5086bea15e1a6/p/include/antlr4-runtime -isystem /home/nicobuzeta/.conan2/p/cerea4cf7b92f85513/p/include -isystem /home/nicobuzeta/.conan2/p/cppzm2f79d96f7bf7d/p/include -isystem /home/nicobuzeta/.conan2/p/b/zerom0e2769d339b1b/p/include -isystem /home/nicobuzeta/.conan2/p/b/gmp8c97d807dd3b9/p/include -isystem /home/nicobuzeta/.conan2/p/b/libpq695142905b307/p/include -isystem /home/nicobuzeta/.conan2/p/b/re2cb33528ec219e/p/include -isystem /home/nicobuzeta/.conan2/p/b/absei0f32c883e8661/p/include -isystem /home/nicobuzeta/Documents/CORE_Project/CORE/build/Debug/_deps/tracy-src/public -m64 -stdlib=libstdc++ -g -g -std=gnu++20 -Werror=old-style-cast -MD -MT CMakeFiles/tests.dir/src/unit_tests/core_server/internal/evaluation/evaluation_algorithm/common.cpp.o -MF CMakeFiles/tests.dir/src/unit_tests/core_server/internal/evaluation/evaluation_algorithm/common.cpp.o.d @CMakeFiles/tests.dir/src/unit_tests/core_server/internal/evaluation/evaluation_algorithm/common.cpp.o.modmap -o CMakeFiles/tests.dir/src/unit_tests/core_server/internal/evaluation/evaluation_algorithm/common.cpp.o -c /home/nicobuzeta/Documents/CORE_Project/CORE/src/unit_tests/core_server/internal/evaluation/evaluation_algorithm/common.cpp
/home/nicobuzeta/Documents/CORE_Project/CORE/src/unit_tests/core_server/internal/evaluation/evaluation_algorithm/common.cpp:1:8: fatal error: module 'foo' not found

```

---

<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:** [November 26, 2023, 3:18pm UTC](https://discourse.cmake.org/t/module-not-found-error-on-3-28/9507/4 "2023-11-26T15:18:13Z")

</div>

> [@nicobuzeta](#):
>
> cmake\_minimum\_required(VERSION 3.28 FATAL\_ERROR)  
> set(CMP0155 NEW)  
> set(CMAKE\_CXX\_SCAN\_FOR\_MODULES ON)

`CMP0155` is a policy, not a variable. Not that either of the `set()` calls matter here given the 3.28 minimum.

> [@nicobuzeta](#):
>
> I’m using conan so I have a build directory /build/Debug/, could this be causing this? I’ve run the basic example with foo.cxx in a different directory and that one works fine.

What do you mean “foo.cxx in a different directory”?

> [@nicobuzeta](#):
>
> `-std=gnu++20`

What version of `clang`?

---

<div class="post-metadata">

**Author:** ![nicobuzeta](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/n/f1d935/32.png) [@nicobuzeta](https://discourse.cmake.org/u/nicobuzeta)\
**Post date:** [November 26, 2023, 6:12pm UTC](https://discourse.cmake.org/t/module-not-found-error-on-3-28/9507/5 "2023-11-26T18:12:11Z")

</div>

I mean I followed this [https://www.kitware.com/import-cmake-the-experiment-is-over/](https://www.kitware.com/import-cmake-the-experiment-is-over/) and the module worked in a new project.

Clang is version 16.0.6.

tests.dir  
[CXXModules.json](https://discourse.cmake.org/uploads/short-url/t65uiyBFYllAKyOTVA3VwhM41aN.json) (161 Bytes)  
[CXXDependInfo.json](https://discourse.cmake.org/uploads/short-url/6fsgoSVDmkhBon5Ac2NR4fC6KEc.json) (1.4 KB)

tests\_modules.dir  
[CXXModules.json](https://discourse.cmake.org/uploads/short-url/t65uiyBFYllAKyOTVA3VwhM41aN.json) (161 Bytes)  
[CXXDependInfo.json](https://discourse.cmake.org/uploads/short-url/6fsgoSVDmkhBon5Ac2NR4fC6KEc.json) (1.4 KB)

[CMakeLists.txt](https://discourse.cmake.org/uploads/short-url/hzwkkC8FV3C77MugmXkrI1iFTW3.txt) (5.2 KB)

---

<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:** [November 26, 2023, 6:16pm UTC](https://discourse.cmake.org/t/module-not-found-error-on-3-28/9507/6 "2023-11-26T18:16:58Z")

</div>

Clang 16 does not support GNU extensions when using modules. Set `CMAKE_CXX_EXTENSIONS` to `OFF` or upgrade to Clang 17.

---

<div class="post-metadata">

**Author:** ![nicobuzeta](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/n/f1d935/32.png) [@nicobuzeta](https://discourse.cmake.org/u/nicobuzeta)\
**Post date:** [November 26, 2023, 6:32pm UTC](https://discourse.cmake.org/t/module-not-found-error-on-3-28/9507/7 "2023-11-26T18:32:48Z")

</div>

I already have:  
set(CMAKE\_CXX\_EXTENSIONS OFF)

In my last post I sent a copy of my CMakeLists.txt.

This is all the settings I have:  
cmake\_minimum\_required(VERSION 3.28 FATAL\_ERROR)

set(CMAKE\_CXX\_STANDARD 20)  
set(CMAKE\_CXX\_STANDARD\_REQUIRED ON)

set(CMAKE\_CXX\_EXTENSIONS OFF)  
set(CMAKE\_CXX\_SCAN\_FOR\_MODULES ON)

---

<div class="post-metadata">

**Author:** ![nicobuzeta](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/n/f1d935/32.png) [@nicobuzeta](https://discourse.cmake.org/u/nicobuzeta)\
**Post date:** [November 26, 2023, 9:06pm UTC](https://discourse.cmake.org/t/module-not-found-error-on-3-28/9507/8 "2023-11-26T21:06:57Z")

</div>

I figured out the problem, I accidently moved the project declaration in the CMakeLists.txt so I had:  
cmake\_minimum\_required(VERSION 3.28 FATAL\_ERROR)

set(CMAKE\_CXX\_STANDARD 20)  
set(CMAKE\_CXX\_STANDARD\_REQUIRED ON)  
set(CMAKE\_CXX\_EXTENSIONS OFF)  
set(CMAKE\_CXX\_SCAN\_FOR\_MODULES ON)

project (core CXX)

I’ve moved the project declaration above those lines and it has fixed all the issues. That said, I am not very familiar with CMake. Why is having the project declaration below those lines break it? Do the settings not get applied unless the project gets declared beforehand?

---

<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:** [November 26, 2023, 11:44pm UTC](https://discourse.cmake.org/t/module-not-found-error-on-3-28/9507/9 "2023-11-26T23:44:06Z")

</div>

> [@nicobuzeta](#):
>
> Why is having the project declaration below those lines break it?

Not sure exactly why these would be “ignored”, but `project` is where CMake detects compilers and sets up support bits based on that. checking those variable values after the `project` might serve some insight.
