[Top][All Lists]

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

The order of compiling multiple c++ source files

From: ljh
Subject: The order of compiling multiple c++ source files
Date: Wed, 10 Aug 2022 04:32:58 +0800

make manual / 10.2 Catalogue of Built-In Rules / Linking a single object file

x: y.o z.o

when x.c, y.c and z.c all exist will execute:

cc -c x.c -o x.o  # x.c compiles first

cc -c y.c -o y.o

cc -c z.c -o z.o

cc x.o y.o z.o -o x

rm -f x.o

rm -f y.o

rm -f z.o



The manual states that the x.c compiles first. 

But in my example code uses C++20 modules with gcc 11.2.0 it compiles last.


rm -f *.o 

deleting object files doesn't happen in my test with gcc 11.2.0 too.

    ` x : y.o z.o ` # without x.o

or this:

    ` x : y.o z.o x.o ` # with x.o

    `    $(CXX) $(LDFLAGS) $^ $(LDLIBS) -o $@ ` # with recipe

The order of compiling is:

g++ -std=c++2a -fmodules-ts -g -c -o y.o c.cpp

g++ -std=c++2a -fmodules-ts -g -c -o z.o b.cpp

g++ -std=c++2a -fmodules-ts -g x.cpp y.o z.o a.o d.o -o x  # x.c compiles last

reply via email to

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