I did not use CPPFLAGS += -Mno-modules , it seems ok after adding it.
Thanks $ pwd /home/ljh/Documents/hello_cpp/src $ $ find . | sed -e 's;[^/]*/;|____;g;s;____|; |;g' . |____notes.txt |____Makefile |____foo | |____bar.cppm | |____foo_impl.cpp | |____foo.cppm | |____Makefile | |____bar_impl.cpp |____main | |____main.cpp | |____Makefile $ $ cat Makefile subdirs = main foo all: $(subdirs) main: foo .PHONY: all clean install $(subdirs) .ONESHELL: $(subdirs): ; @$(MAKE) -C $@ clean: @for dir in $(subdirs) do $(MAKE) -C $$dir $@ done $ $ cat foo/Makefile # build dynamic library with -fPIC -shared CXXFLAGS = -g -fPIC -std=c++23 -fmodules # -O3 # CXXFLAGS for .cpp CPPFLAGS = -MMD -MP -Mno-modules # -I../foo -DNDEBUG LDFLAGS = -shared # -L../foo -static LDLIBS = # -lfoo CC = $(CXX) # link with CXX for .cpp all: foo libfoo.so libfoo.so: foo; cp foo libfoo.so foo_impl.o: foo.o bar_impl.o: bar.o # target name is basename of one of the source files foo: $(addsuffix .o,$(basename $(wildcard *.c *.cpp *.cppm))) # .cpp -include *.d clean: ; rm -fr *.o *.d foo libfoo.so gcm.cache .PHONY: clean %.o :%.cppm ; $(COMPILE.cpp) $(OUTPUT_OPTION) $< $ $ cat main/Makefile # build dynamic library with -fPIC -shared CXXFLAGS = -g -std=c++23 -fmodules # -O3 -fPIC # CXXFLAGS for .cpp CPPFLAGS = -MMD -MP -Mno-modules -I../foo # -DNDEBUG LDFLAGS = -L../foo # -shared -static LDLIBS = -lfoo CC = $(CXX) # link with CXX for .cpp all: main # target name is basename of one of the source files main: $(addsuffix .o,$(basename $(wildcard *.c *.cpp *.cppm))) # .cpp -include *.d clean: ; rm -fr *.o *.d main .PHONY: clean CXXFLAGS += '-fmodule-mapper=|@g++-mapper-server -r../foo/gcm.cache' %.c++-module: ; $ $ make make[1]: Entering directory '/home/ljh/Documents/hello_cpp/src/foo' g++ -g -fPIC -std=c++23 -fmodules -MMD -MP -Mno-modules -c -o foo.o foo.cppm g++ -g -fPIC -std=c++23 -fmodules -MMD -MP -Mno-modules -c -o bar.o bar.cppm g++ -g -fPIC -std=c++23 -fmodules -MMD -MP -Mno-modules -c -o bar_impl.o bar_impl.cpp g++ -g -fPIC -std=c++23 -fmodules -MMD -MP -Mno-modules -c -o foo_impl.o foo_impl.cpp g++ -shared foo.o bar_impl.o foo_impl.o bar.o -o foo cp foo libfoo.so make[1]: Leaving directory '/home/ljh/Documents/hello_cpp/src/foo' make[1]: Entering directory '/home/ljh/Documents/hello_cpp/src/main' g++ -g -std=c++23 -fmodules '-fmodule-mapper=|@g++-mapper-server -r../foo/gcm.cache' -MMD -MP -Mno-modules -I../foo -c -o main.o main.cpp g++ -L../foo main.o -lfoo -o main make[1]: Leaving directory '/home/ljh/Documents/hello_cpp/src/main' $ $ make make[1]: Entering directory '/home/ljh/Documents/hello_cpp/src/foo' make[1]: Nothing to be done for 'all'. make[1]: Leaving directory '/home/ljh/Documents/hello_cpp/src/foo' make[1]: Entering directory '/home/ljh/Documents/hello_cpp/src/main' make[1]: Nothing to be done for 'all'. make[1]: Leaving directory '/home/ljh/Documents/hello_cpp/src/main' $ $
