#Can't compile with C++20 modules feature

17 messages · Page 1 of 1 (latest)

weak belfry
#

I migrated my project files from .cpp/.h to .cppm but the compiler says

Arcranion.Window: error: failed to read compiled module: no such file or directory
Arcranion.Window: note: compiled module file is ‘gcm.cache/Arcranion.Window.gcm’
Arcranion.Window: note: imports must be built before being imported
Arcranion.Window: fatal error: returning to the gate for a mechanical issues
wet wigeonBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

weak belfry
#

Platform Ubuntu 22.04
Compiler GCC 11.4.0

#
cmake_minimum_required(VERSION 3.22)
project(Arcranion)

set(CMAKE_CXX_STANDARD 20)

# Compiler
set(CMAKE_CXX_COMPILER "gcc")
add_compile_options(-fmodules-ts)

link_directories(library)

add_executable(Arcranion
        source/main.cpp
        source/engine/application/description.h
        source/engine/util/version.h
        source/engine/util/util.h
        source/engine/arcranion.cppm
        source/engine/extensions.cppm
        source/engine/application/application.h
        source/engine/window/window.cppm
        source/engine/application/launcher.h
        source/engine/instance/instance.h
        source/engine/variables/engine.h
)

target_link_libraries(Arcranion
        glfw3
        spdlog
        fmt
        vulkan
        dl
        m
        X11
)

CMakeList.txt

#
import Arcranion.Window;

int main() {
...
}

main.cpp

#

The project structure

#
====================[ 빌드 | Arcranion | Debug ]==================================
/media/devlaq/LocalDisk/Jetbrains/apps/CLion/ch-0/232.8660.186/bin/cmake/linux/x64/bin/cmake --build /home/devlaq/CLionProjects/Arcranion/cmake-build-debug --target Arcranion -j 14
[1/5] Building CXX object CMakeFiles/Arcranion.dir/source/engine/arcranion.cppm.o
gcc: warning: /home/devlaq/CLionProjects/Arcranion/source/engine/arcranion.cppm: linker input file unused because linking not done
[2/5] Building CXX object CMakeFiles/Arcranion.dir/source/engine/extensions.cppm.o
gcc: warning: /home/devlaq/CLionProjects/Arcranion/source/engine/extensions.cppm: linker input file unused because linking not done
[3/5] Building CXX object CMakeFiles/Arcranion.dir/source/engine/window/window.cppm.o
gcc: warning: /home/devlaq/CLionProjects/Arcranion/source/engine/window/window.cppm: linker input file unused because linking not done
[4/5] Building CXX object CMakeFiles/Arcranion.dir/source/main.cpp.o
FAILED: CMakeFiles/Arcranion.dir/source/main.cpp.o 
gcc   -g -std=gnu++20 -fdiagnostics-color=always -fmodules-ts -MD -MT CMakeFiles/Arcranion.dir/source/main.cpp.o -MF CMakeFiles/Arcranion.dir/source/main.cpp.o.d -o CMakeFiles/Arcranion.dir/source/main.cpp.o -c /home/devlaq/CLionProjects/Arcranion/source/main.cpp
In module imported at /home/devlaq/CLionProjects/Arcranion/source/main.cpp:1:1:
Arcranion.Window: error: failed to read compiled module: 그런 파일이나 디렉터리가 없습니다
Arcranion.Window: note: compiled module file is ‘gcm.cache/Arcranion.Window.gcm’
Arcranion.Window: note: imports must be built before being imported
Arcranion.Window: fatal error: returning to the gate for a mechanical issue
compilation terminated.
ninja: build stopped: subcommand failed.

The full error code.
How can I fix this? I'm spending too many hours in this and I can't get no more progress

timid brook
#

@weak belfry well the fastest non-fix would be not to use modules with cmake+gcc, modules support just isn't ready, and just time I checked the specific combo of tools you have was really annoying to get going

#

Last I checked (couple months ago) modules support for both GCC and cmake was experimental
Gcc11 has some of the functionalities for modules, sufficiently even to get something going, but only if you compile "manually"

#

The modules system requires that your files are processed in a specific order, which is the dependency order between modules
That constraint is completely new since the header system allowed you to just compile anything in any order (at the cost of doing the same bit of work multiple times), which made for much simpler work for cmake

#

The way things are shaping out, cmake wants compiler providers to expose tools/api to enable cmake to figure out the right order

#

msvc already ships that functionality, so if you were using msvc you could add a couple of lines in your cmakelist to try out that new functionality and cmake modules support

#

With gcc, that compiler feature was on some branch that you'd have to fork and compile iirc

#

If you're motivated to go all the way and get GCC + cmake working, I'll try to find the link to the article/blog post again, though I think it was one of the first result for googling cmake modules support

#
#

This is dated from January 2023 so with some luck, GCC was updated and there's an easier way to grab the right version

weak belfry
#

Thanks so much for writing such a long answer, I read the article you sent. building the gcc fork now i'll tell you when I come back