It is said in docs that modules support in CLang is partial. I'm using CLang under Windows 64-bit from recent release of LLVM 12.0.
I successfully managed to use regular modules, (that you import through import modulename;).
But I haven't managed to create and use header unit modules, those that you import through import "header.hpp";. Can you suggest how to do that with examples?
For trying header units I created next toy files:
hello.hpp:
#include <vector>
use.cpp:
import "hello.hpp";
int main() {
std::vector<int> v(123);
}
Then I successfully (I hope) compiled header unit hello.hpp into PCM file:
clang++ -std=c++20 -Xclang -emit-header-module -I. hello.hpp -o hello.pcm
Command ran without errors and produced hello.pcm. If you run command above without -o flag then file
hello.hpp.gch is created.
Then I tried to compile use.cpp, but without success, somehow it can't recognize my header unit and/or can't find corresponding hello.pcm. I think I'm missing some special flags that show compiler that it is header unit. Next command was used:
clang++ -std=c++20 -fprebuilt-module-path=. -fmodule-file=hello.hpp=hello.pcm -I. use.cpp
Which gave compile error:
use.cpp:1:8: error: header file "hello.hpp" (aka './hello.hpp') cannot be imported because it is not known to be a header unit
import "hello.hpp";
^
Under MSVC I successfully managed to use regular modules and header unit modules. But not in CLang. Can you help me with that? Or tell me maybe CLang header units are not yet supported.