A Partitioned Module (Javanese) (WIP)
Module Interface Unit: Javanese
1 module;
2
3 export module Javanese;
4 export import :Balinese; // exports all from :Balinese
5
6 export auto meow() -> void; // from javanese.cpp
Module Implementation Unit: Javanese
1 module;
2
3 #include <print>
4
5 module Javanese;
6
7 auto meow() -> void {
8 std::println("Kucing jawa ngomong 'mbelong'");
9 }
Partition Module Interface Unit: Balinese
1 module;
2
3 export module Javanese:Balinese;
4
5 export namespace Balinese {
6 auto meong() -> void;
7 }
Partition Module Implementation Unit: Balinese
1 module;
2
3 #include <print>
4
5 module Javanese:Balinese;
6
7 namespace Balinese {
8 auto meong() -> void {
9 std::println("Balinese anak kucing says 'meong'");
10 }
11 }
User Code: main
1 import Javanese;
2
3 auto main() -> int {
4 meow();
5 Balinese::meong();
6
7 return 0;
8 }
Building Javanese Partition Module
Building Javanese with GCC
1 + g++ -std=c++23 -fmodules-ts -c -x c++ Balinese.cppm -o bin/Balinese.o
2 + g++ -std=c++23 -fmodules-ts -c -x c++ Javanese.cppm -o bin/Javanese.o
3 + g++ -std=c++23 -fmodules-ts -c javanese.cpp -o bin/javanese.o
4 + g++ -std=c++23 -fmodules-ts -c balinese.cpp -o bin/balinese.o
5 + ar rcs bin/libJavanese.a bin/Javanese.o bin/Balinese.o bin/javanese.o bin/balinese.o
6 + g++ -std=c++23 -fmodules-ts -c main.cpp -o bin/main.o
7 + g++ -std=c++23 -fmodules-ts bin/main.o -Lbin -lJavanese -o bin/main
Building Javanese with Clang
1 + clang++ -std=c++23 --precompile Balinese.cppm -o bin/Javanese-Balinese.pcm
2 + clang++ -std=c++23 --precompile -fprebuilt-module-path=bin Javanese.cppm -o bin/Javanese.pcm
3 + clang++ -std=c++23 -c -fprebuilt-module-path=bin Javanese.cppm -o bin/Javanese.o
4 + clang++ -std=c++23 -c -fprebuilt-module-path=bin javanese.cpp -o bin/javanese.o
5 + clang++ -std=c++23 -c -fprebuilt-module-path=bin balinese.cpp -o bin/balinese.o
6 + clang++ -std=c++23 -r bin/Javanese.o bin/javanese.o bin/balinese.o -o bin/Javanese.Module.o
7 + clang++ -std=c++23 -c -fprebuilt-module-path=bin main.cpp -o bin/main.o
8 + clang++ -std=c++23 bin/Javanese.Module.o bin/main.o -o bin/main
Building with CMake
Here is the script. See Parent Directory CMakelist.txt for the parent directory file. Section: Parent Directory CMakelist.txt
1 cmake_minimum_required(VERSION 3.30.5)
2 project(Javanese LANGUAGES CXX)
3 set(module_name javanese)
4
5 add_executable(${PROJECT_NAME} main.cpp)
6 target_link_libraries(${PROJECT_NAME} ${module_name})
7
8 add_library(${module_name})
9 target_compile_features(${module_name} PUBLIC cxx_std_23)
10 target_sources(${module_name}
11 PUBLIC
12 FILE_SET cxx_modules TYPE CXX_MODULES
13 FILES
14 Balinese.cppm
15 ${PROJECT_NAME}.cppm
16 PRIVATE
17 ${module_name}.cpp
18 balinese.cpp
19 )