Cannot find multiple module files using add_module_library.
Closed this issue · 1 comments
tonadr1022 commented
After getting the minimal example in the README (Clang, in source build) to work using the exact commands and files, I've been unable to add another file to the project using add_module_library(hello hello.cc hello2.cc)
.
Here is hello2.cc:
module;
#include <cstdio>
export module hello2;
export void hello2() { std::printf("hello2, modules!\n"); }
Here is main.cc
import hello;
import hello2;
int main() {
hello();
hello2();
}
Here is the output
[ 71%] Built target hello
[ 85%] Building CXX object CMakeFiles/main.dir/main.cc.o
/Users/tony/dep/cpp/modules/ex2/main.cc:1:8: fatal error: error in loading module 'hello' from prebuilt module path
1 | import hello;
| ^
1 error generated.
make[2]: *** [CMakeFiles/main.dir/main.cc.o] Error 1
make[1]: *** [CMakeFiles/main.dir/all] Error 2
make: *** [all] Error 2
And here is the full CMakeLists.txt
cmake_minimum_required(VERSION 3.11)
project(HELLO CXX)
include(modules.cmake)
add_module_library(hello hello.cc hello2.cc)
add_executable(main main.cc)
target_link_libraries(main hello)
The .pcm and .o files are generated for hello2.cc, but it isn't seen by the executable.
vitaut commented
add_module_library
only supports building libraries similarly to CMake add_library
. For an executable you'll need to use a separate CMake target.