[Top][All Lists]

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

Re: The order of compiling multiple c++ source files

From: Paul Smith
Subject: Re: The order of compiling multiple c++ source files
Date: Tue, 09 Aug 2022 18:17:21 -0400
User-agent: Evolution 3.44.3 (by Flathub.org)

On Wed, 2022-08-10 at 04:32 +0800, ljh wrote:
> make manual / 10.2 Catalogue of Built-In Rules / Linking a single
> object file

The example in the manual is wrong.  The output you're getting from GNU
make is correct.

The reason is that the implicit rule that make chooses for the rule:

  x: y.o z.o

is not "%.o : %.c" followed by "% : %.o".

Instead, make chooses the default rule "% : %.c" which knows how to
create a binary directly from an similarly-named .c file.  You'll note
in your output that the link line is:

  g++ ... x.cpp y.o z.o a.o d.o -o x

see how you have "x.cpp" on the link line, not "x.o"?  And there's no
"x.o" in your directory.

This may not be what you want, but it's a perfectly valid way to build

As for the "rm" that's clearly just wrong: since these objects are
mentioned as prerequisites they cannot be considered intermediate and
won't be deleted.

So, the manual example needs to be fixed.

reply via email to

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