Sample Header Ad - 728x90

Why touching just one source, make recompiles again the other untouched source file?

1 vote
1 answer
293 views
Just touching file mod1.c, make should just recompile that source file, produce its correspondent object file, mod1.o, and should not recompile mod2.c, because the object file mod2.o will be still completely up to date (mod2.c is, as untouched, yet older than mod2.o, so no need to recompile). But I get the following behavior:
(This is not a personal creation, is from a written example from a source on make [saying the text that one will witness how make knows that mod2.c is untouched and will not recompile it]). **Makefile** $ cat Makefile SRC = mod1.c mod2.c main.c OBJ = mod1.o mod2.o main.o PROG = dbtest $(PROG): $(OBJ) gcc $(OBJ) -o $(PROG) $(OBJ): $(SRC)
**The problem:** $ make make: 'dbtest' is up to date. $ touch mod1.c $ make cc -c -o mod1.o mod1.c cc -c -o mod2.o mod2.c cc -c -o main.o main.c gcc mod1.o mod2.o main.o -o dbtest **Files contents** $ cat mod1.c #include void foo() { printf("Hello "); } $ cat mod2.c #include void bar() { printf(“World\n”); }
$ cat main.c #include void foo(); void bar(); int main (void) { foo(); bar(); return 0; }
Asked by nostromo (113 rep)
Aug 27, 2024, 04:25 PM
Last activity: Aug 27, 2024, 04:49 PM