Skip to content

Instantly share code, notes, and snippets.

@Necklaces
Forked from vladiant/Makefile
Created July 18, 2022 10:34
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 Necklaces/7077a3ef6490960768c67d6b5437efa0 to your computer and use it in GitHub Desktop.
Save Necklaces/7077a3ef6490960768c67d6b5437efa0 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