bug-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: »Ø¸´£º Implicit rule for linking multiple object files


From: Henrik Carlqvist
Subject: Re: »Ø¸´£º Implicit rule for linking multiple object files
Date: Thu, 11 Aug 2022 08:52:05 +0200

On Thu, 11 Aug 2022 14:18:29 +0800
"ljh" <ljhm@qq.com> wrote:

> main : c.o b.o a.o d.o main.o

> 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

With the compiler anc C++ language you are using it seems as if it is required
that a.o, b.o, c.o and/or d.o is built before main.o. If so, you will need to
specify a dependency like this:

main.o: a.o b.o c.o d.o

> 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

That Makefile might seem fine and seem to work, but what would happen if you
would run "make -j 5"? Then, again, those other object files would not have
been built before main.o. So to work correctly with parallell builds, that
Makefile would probably also need a rule like:

main.o: a.o b.o c.o d.o

regards Henrik



reply via email to

[Prev in Thread] Current Thread [Next in Thread]