Skip to content

Instantly share code, notes, and snippets.

@andijcr
Created March 8, 2022 16:47
Show Gist options
  • Save andijcr/ee1d0962692f1aca94b64cbd7bdd0066 to your computer and use it in GitHub Desktop.
Save andijcr/ee1d0962692f1aca94b64cbd7bdd0066 to your computer and use it in GitHub Desktop.
gcc 11 module example
export module helloworld; // module declaration
import <iostream>; // import declaration
export void hello() { // export declaration
std::cout << "Hello world!\n";
}
import helloworld; // import declaration
int main() {
hello();
}
all: hello
gcm.cache:
g++ -std=c++20 -fmodules-ts -xc++-system-header iostream
helloworld.o: helloworld.cxx gcm.cache
g++ -std=c++20 -fmodules-ts -c helloworld.cxx -o helloworld.o
hello: helloworld.o
g++ -std=c++20 -fmodules-ts main.cpp helloworld.o -o hello
clean:
rm -fr gcm.cache
rm -f helloworld.o hello
.PHONY: all clean
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment