Hi Paul,

I don't know if this is related to gcc support of c++20. 
But mentioning target.o ("x.o") and recipe or not in my Makefile, does have 
different result. My test follows.


Thanks




---


1. error: with target.o ("x.o"), without recipe




$ ls
 a.cpp   b.cpp   c.cpp   d.cpp   main.cpp   
Makefile
$
$ cat Makefile
CXXFLAGS = -Wall -Wextra -std=c++2a -fmodules-ts -g # -O3 -fPIC
main : c.o b.o a.o d.o main.o
#       $(CXX) $^ -o $@
$ make
g++ -Wall -Wextra -std=c++2a -fmodules-ts -g    -c -o main.o main.cpp
In module imported at main.cpp:1:1:
A: error: failed to read compiled module: No such file or directory
A: note: compiled module file is ??gcm.cache/A.gcm??
A: note: imports must be built before being imported
A: fatal error: returning to the gate for a mechanical issue
compilation terminated.
make: *** [<builtin&gt;: main.o] Error 1
$&nbsp;




2. ok: without target.o and recipe




$ rm -fr *.o gcm.cache main
$ cat Makefile
CXXFLAGS = -Wall -Wextra -std=c++2a -fmodules-ts -g # -O3 -fPIC
main : c.o b.o a.o d.o # main.o
# &nbsp; &nbsp; &nbsp; $(CXX) $^ -o $@
$ make
g++ -Wall -Wextra -std=c++2a -fmodules-ts -g &nbsp; &nbsp;-c -o c.o c.cpp
g++ -Wall -Wextra -std=c++2a -fmodules-ts -g &nbsp; &nbsp;-c -o b.o b.cpp
g++ -Wall -Wextra -std=c++2a -fmodules-ts -g &nbsp; &nbsp;-c -o a.o a.cpp
g++ -Wall -Wextra -std=c++2a -fmodules-ts -g &nbsp; &nbsp;-c -o d.o d.cpp
g++ -Wall -Wextra -std=c++2a -fmodules-ts -g &nbsp; &nbsp; main.cpp c.o b.o a.o 
d.o &nbsp; -o main
$&nbsp;




3. ok: with target.o and recipe




$ rm -fr *.o gcm.cache main
$ cat Makefile
CXXFLAGS = -Wall -Wextra -std=c++2a -fmodules-ts -g # -O3 -fPIC
main : c.o b.o a.o d.o main.o
&nbsp; &nbsp; &nbsp; &nbsp; $(CXX) $^ -o $@
$ make
g++ -Wall -Wextra -std=c++2a -fmodules-ts -g &nbsp; &nbsp;-c -o c.o c.cpp
g++ -Wall -Wextra -std=c++2a -fmodules-ts -g &nbsp; &nbsp;-c -o b.o b.cpp
g++ -Wall -Wextra -std=c++2a -fmodules-ts -g &nbsp; &nbsp;-c -o a.o a.cpp
g++ -Wall -Wextra -std=c++2a -fmodules-ts -g &nbsp; &nbsp;-c -o d.o d.cpp
g++ -Wall -Wextra -std=c++2a -fmodules-ts -g &nbsp; &nbsp;-c -o main.o main.cpp
g++ c.o b.o a.o d.o main.o -o main
$&nbsp;


$ make --version
GNU Make 4.3
Built for x86_64-pc-linux-gnu
Copyright (C) 1988-2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html&gt;
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
$&nbsp;





------------------&nbsp;????????&nbsp;------------------
??????: "psmith"<psm...@gnu.org&gt;; 
????????: 2022??8??11??(??????) ????2:31
??????: "ljh"<l...@qq.com&gt;; "bug-make"<bug-make@gnu.org&gt;; 
????: Re: Implicit rule for linking multiple object files



On&nbsp;Thu,&nbsp;2022-08-11&nbsp;at&nbsp;01:58&nbsp;+0800,&nbsp;ljh&nbsp;wrote:
&gt;&nbsp;I&nbsp;have&nbsp;three&nbsp;c&nbsp;source&nbsp;files:&nbsp;x.c,&nbsp;y.c,&nbsp;z.c&nbsp;and&nbsp;I&nbsp;name&nbsp;x&nbsp;as&nbsp;the&nbsp;target
&gt;&nbsp;on&nbsp;left.&nbsp;Can&nbsp;I&nbsp;put&nbsp;x.o&nbsp;in&nbsp;the&nbsp;prerequisites&nbsp;on&nbsp;the&nbsp;right&nbsp;too?&nbsp;Are
&gt;&nbsp;they&nbsp;the&nbsp;same,&nbsp;with&nbsp;or&nbsp;without&nbsp;x.o&nbsp;in&nbsp;the&nbsp;prerequisites&nbsp;on&nbsp;the&nbsp;right?
&gt;&nbsp;?0?2&nbsp;?0?2
&gt;&nbsp;?0?2&nbsp;?0?2&nbsp;x:&nbsp;y.o&nbsp;z.o&nbsp;x.o&nbsp;?0?2#&nbsp;with&nbsp;x.o

It&nbsp;is&nbsp;correct&nbsp;to&nbsp;do&nbsp;this.

These&nbsp;two&nbsp;rules&nbsp;do&nbsp;not&nbsp;behave&nbsp;exactly&nbsp;the&nbsp;same:

&nbsp;&nbsp;x:&nbsp;y.o&nbsp;z.o

versus

&nbsp;&nbsp;x:&nbsp;y.o&nbsp;z.o&nbsp;x.o

(you&nbsp;can&nbsp;see&nbsp;the&nbsp;difference&nbsp;for&nbsp;yourself&nbsp;by&nbsp;running&nbsp;&quot;make&quot;&nbsp;both&nbsp;ways)
but&nbsp;the&nbsp;result&nbsp;of&nbsp;both&nbsp;of&nbsp;these&nbsp;will&nbsp;give&nbsp;you&nbsp;the&nbsp;same&nbsp;working&nbsp;program.

&gt;&nbsp;Is&nbsp;it&nbsp;correct&nbsp;for&nbsp;me&nbsp;to&nbsp;use&nbsp;patsubst&nbsp;function&nbsp;to&nbsp;include&nbsp;all&nbsp;object
&gt;&nbsp;files?
&gt;&nbsp;?0?2&nbsp;?0?2&nbsp;x:&nbsp;$(patsubst&nbsp;%.c,%.o,$(wildcard&nbsp;*.c))

This&nbsp;is&nbsp;fine&nbsp;too.

&gt;&nbsp;In&nbsp;my&nbsp;test&nbsp;the&nbsp;rule&nbsp;with&nbsp;patsubst&nbsp;works&nbsp;on&nbsp;most&nbsp;cases.&nbsp;But&nbsp;if&nbsp;my&nbsp;code
&gt;&nbsp;uses&nbsp;C++20&nbsp;modules,&nbsp;I&nbsp;need&nbsp;to&nbsp;omit&nbsp;x.o&nbsp;if&nbsp;I&nbsp;want&nbsp;to&nbsp;omit&nbsp;the&nbsp;recipe:
&gt;&nbsp;?0?2&nbsp;?0?2&nbsp;x:&nbsp;y.o&nbsp;z.o&nbsp;?0?2#&nbsp;without&nbsp;x.o&nbsp;and&nbsp;recipe
&gt;&nbsp;
&gt;&nbsp;if&nbsp;I&nbsp;include&nbsp;x.o,&nbsp;I&nbsp;can&#39;t&nbsp;omit&nbsp;the&nbsp;recipe:
&gt;&nbsp;?0?2&nbsp;?0?2&nbsp;`&nbsp;x:&nbsp;y.o&nbsp;z.o&nbsp;x.o&nbsp;`&nbsp;#&nbsp;with&nbsp;x.o?0?2
&gt;&nbsp;?0?2&nbsp;?0?2&nbsp;`&nbsp;?0?2&nbsp;?0?2$&nbsp;(CXX)&nbsp;$&nbsp;(LDFLAGS)&nbsp;$^&nbsp;$(LDLIBS)&nbsp;-o&nbsp;$@&nbsp;`&nbsp;#&nbsp;with&nbsp;recipe

I&nbsp;don&#39;t&nbsp;know&nbsp;why&nbsp;you&nbsp;keep&nbsp;referring&nbsp;to&nbsp;C++20&nbsp;modules.&nbsp;&nbsp;Make&nbsp;doesn&#39;t
know&nbsp;anything&nbsp;about&nbsp;C++20&nbsp;modules,&nbsp;it&nbsp;doesn&#39;t&nbsp;even&nbsp;know&nbsp;what&nbsp;version&nbsp;of
C++&nbsp;the&nbsp;compiler&nbsp;is&nbsp;building&nbsp;with.&nbsp;&nbsp;It&nbsp;barely&nbsp;even&nbsp;knows&nbsp;that&nbsp;there&nbsp;is
such&nbsp;a&nbsp;thing&nbsp;as&nbsp;C++:&nbsp;all&nbsp;it&nbsp;knows&nbsp;is&nbsp;&quot;some&nbsp;source&nbsp;files&nbsp;end&nbsp;in&nbsp;.cpp&nbsp;or
.cc&nbsp;or&nbsp;.cxx&nbsp;and&nbsp;those&nbsp;should&nbsp;be&nbsp;built&nbsp;with&nbsp;a&nbsp;recipe&nbsp;that&nbsp;uses&nbsp;variables
CXX&nbsp;and&nbsp;CXXFLAGS&quot;.

In&nbsp;any&nbsp;event,&nbsp;I&nbsp;see&nbsp;no&nbsp;reason&nbsp;why&nbsp;an&nbsp;implicit&nbsp;rule&nbsp;without&nbsp;a&nbsp;recipe&nbsp;and
with&nbsp;x.o&nbsp;as&nbsp;a&nbsp;prerequisite&nbsp;wouldn&#39;t&nbsp;work.&nbsp;&nbsp;In&nbsp;fact,&nbsp;it&nbsp;works&nbsp;fine&nbsp;for
me:

&nbsp;&nbsp;$&nbsp;ls
&nbsp;&nbsp;Makefile&nbsp;&nbsp;x.c&nbsp;&nbsp;y.c&nbsp;&nbsp;z.c

&nbsp;&nbsp;$&nbsp;cat&nbsp;Makefile
&nbsp;&nbsp;x:&nbsp;$(patsubst&nbsp;%.c,%.o,$(wildcard&nbsp;*.c))

&nbsp;&nbsp;$&nbsp;make
&nbsp;&nbsp;cc&nbsp;&nbsp;&nbsp;&nbsp;-c&nbsp;-o&nbsp;x.o&nbsp;x.c
&nbsp;&nbsp;cc&nbsp;&nbsp;&nbsp;&nbsp;-c&nbsp;-o&nbsp;y.o&nbsp;y.c
&nbsp;&nbsp;cc&nbsp;&nbsp;&nbsp;&nbsp;-c&nbsp;-o&nbsp;z.o&nbsp;z.c
&nbsp;&nbsp;cc&nbsp;&nbsp;&nbsp;x.o&nbsp;y.o&nbsp;z.o&nbsp;&nbsp;&nbsp;-o&nbsp;x

Reply via email to