-
Notifications
You must be signed in to change notification settings - Fork 15.2k
Closed
Labels
clang:modulesC++20 modules and Clang Header ModulesC++20 modules and Clang Header Modulesplatform:windows
Description
The documentation here provides the following Hello-World style example:
// M.cppm
export module M;
export import :interface_part;
import :impl_part;
export void Hello();
// interface_part.cppm
export module M:interface_part;
export void World();
// impl_part.cppm
module;
#include <iostream>
#include <string>
module M:impl_part;
import :interface_part;
std::string W = "World.";
void World() {
std::cout << W << std::endl;
}
// Impl.cpp
module;
#include <iostream>
module M;
void Hello() {
std::cout << "Hello ";
}
// User.cpp
import M;
int main() {
Hello();
World();
return 0;
}
Precompiling the module
clang++ -std=c++20 interface_part.cppm --precompile -o M-interface_part.pcm
clang++ -std=c++20 impl_part.cppm --precompile -fprebuilt-module-path=. -o M-impl_part.pcm
clang++ -std=c++20 M.cppm --precompile -fprebuilt-module-path=. -o M.pcm
clang++ -std=c++20 Impl.cpp -fmodule-file=M.pcm -c -o Impl.o
Compiling the user
clang++ -std=c++20 User.cpp -fprebuilt-module-path=. -c -o User.o
Compiling the module and linking it together
clang++ -std=c++20 M-interface_part.pcm -c -o M-interface_part.o
clang++ -std=c++20 M-impl_part.pcm -c -o M-impl_part.o
clang++ -std=c++20 M.pcm -c -o M.o
clang++ User.o M-interface_part.o M-impl_part.o M.o Impl.o -o a.out
I tried this exact example on LLVM 15.0.7 for 64-bit Windows. The files are included. The standard library and linker/backend in my environment is MSVC 17.5.1. I have changed the command lines slightly for Windows. The result is a strange failure at Impl.cpp
:
Impl.cpp:5:3: error: use of undeclared identifier 'std'
std::cout << "Hello ";
^
1 error generated.
Note, I can compile, link and execute a regular "Hello World" (without C++20 modules) in my LLVM environment just fine, it is only behaving this way when it imports modules and includes system headers in global module fragments of those imported modules.
test2.zip
Metadata
Metadata
Assignees
Labels
clang:modulesC++20 modules and Clang Header ModulesC++20 modules and Clang Header Modulesplatform:windows