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) $<
$&nbsp;
$ cat main/Makefile&nbsp;
# build dynamic library with -fPIC -shared
CXXFLAGS&nbsp; &nbsp;= -g -std=c++23 -fmodules # -O3 -fPIC # CXXFLAGS for .cpp
CPPFLAGS = -MMD -MP -Mno-modules -I../foo # -DNDEBUG
LDFLAGS&nbsp; = -L../foo # -shared -static
LDLIBS&nbsp; &nbsp;= -lfoo
CC&nbsp; &nbsp; &nbsp; = $(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: ;
$&nbsp;
$ make
make[1]: Entering directory '/home/ljh/Documents/hello_cpp/src/foo'
g++ -g -fPIC -std=c++23 -fmodules&nbsp; -MMD -MP -Mno-modules&nbsp; &nbsp;-c -o 
foo.o foo.cppm
g++ -g -fPIC -std=c++23 -fmodules&nbsp; -MMD -MP -Mno-modules&nbsp; &nbsp;-c -o 
bar.o bar.cppm
g++ -g -fPIC -std=c++23 -fmodules&nbsp; -MMD -MP -Mno-modules&nbsp; &nbsp;-c -o 
bar_impl.o bar_impl.cpp
g++ -g -fPIC -std=c++23 -fmodules&nbsp; -MMD -MP -Mno-modules&nbsp; &nbsp;-c -o 
foo_impl.o foo_impl.cpp
g++&nbsp; -shared&nbsp; &nbsp;foo.o bar_impl.o foo_impl.o bar.o&nbsp; &nbsp;-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&nbsp; '-fmodule-mapper=|@g++-mapper-server 
-r../foo/gcm.cache' -MMD -MP -Mno-modules -I../foo&nbsp; &nbsp;-c -o main.o 
main.cpp
g++&nbsp; -L../foo&nbsp; &nbsp;main.o&nbsp; -lfoo -o main
make[1]: Leaving directory '/home/ljh/Documents/hello_cpp/src/main'
$&nbsp;
$ 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'
$&nbsp;
$&nbsp;

Reply via email to