Skip to content

Instantly share code, notes, and snippets.

@vladiant
Created July 10, 2021 22:12
Show Gist options
  • Save vladiant/caeaa24e32e0488ab5199d10d4d74ea0 to your computer and use it in GitHub Desktop.
Save vladiant/caeaa24e32e0488ab5199d10d4d74ea0 to your computer and use it in GitHub Desktop.
C++20 Hello World Module
https://github.com/steve-downey/module-hw/blob/master/main.cpp
// hello.cpp
module;
#include <iostream>
#include <string_view>
export module smd.hello;
export namespace hello {
void hello(std::string_view name)
{
std::cout << "Hello, " << name << "! \n";
}
} // namespace hello
// main.cxx
import smd.hello;
int main()
{
hello::hello("Steve");
}
main : main.o hello.o
g++-11 -o main main.o hello.o
main.o : main.cpp gcm.cache/smd.hello.gcm
g++-11 -fPIC -fmodules-ts -std=c++20 -o main.o -c main.cpp
hello.o: hello.cpp
g++-11 -fPIC -fmodules-ts -std=c++20 -o hello.o -c hello.cpp
gcm.cache/smd.hello.gcm: hello.o
@test -f $@ || rm -f $<
@test -f $@ || $(MAKE) $<
clean:
rm hello.o main.o gcm.cache/smd.hello.gcm
clean-gcm:
rm gcm.cache/smd.hello.gcm
test:
./main
all: main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment