Skip to content

Instantly share code, notes, and snippets.

@heapwolf
Created April 29, 2021 08:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save heapwolf/5a33659fd65c0bbe7bc43baa2c362b86 to your computer and use it in GitHub Desktop.
Save heapwolf/5a33659fd65c0bbe7bc43baa2c362b86 to your computer and use it in GitHub Desktop.
#
# clean up any existing artifacts
#
rm -rf build/dist
mkdir -p build/dist >/dev/null 2>&1
#
# compile a module
#
clang++ -std=c++2a \
-c hello.cxx \
-fmodules \
-Xclang -emit-module-interface \
-o build/hello.pcm
#
# compile the code that uses it
#
clang++ -std=c++2a \
-fmodules \
-fprebuilt-module-path=build \
main.cxx \
hello.cxx \
-o build/dist/hello \
-fmodule-file=helloworld=build/hello.pcm
#
# run it
#
./build/dist/hello
export module helloworld;
export namespace helloworld {
auto hello () {
return "Hello, world";
}
}
import <iostream>;
import helloworld;
int main() {
std::cout << helloworld::hello() << std::endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment