Makefile: Getting "`target' is up to date"
Asked Answered
M

2

6

I have made a makefile for some c files. I have seen too many ways on the internet but i had always the same problem: Running make, I am told:

make: `q_a' is up to date.

My Makefile contains:

q_a: 
gcc -o q_a quick_sort_i.c

q_g: 
gcc -o q_g quick_sort_g.c

s_a: 
gcc -o s_a shell_sort_i.c

s_g: 
gcc -o s_g shell_sort_g.c

fork: 
gcc -o fork fork.c

I don't have files with the same name as the target in my folder, and I can perform the compilation commands successfully them when I enter them manually in a terminal.

Mm answered 15/2, 2014 at 8:17 Comment(1)
FYI: have you tried CMake? This tool could greatly simplify your "Makefiles".Canzone
B
13

You have not specified dependencies for your targets.

What make does, is first checking if your target (q_a) exists as a file, and if it does, if its dependencies are newer (as in, have more recent modification time) as your target. Only if it needs to be updated (it does not exist or dependencies are newer) the rule is executed.

That means, if you need q_a to be recompiled every time quick_sort_i.c is changed, you need to add it as a dependency to q_a, like this:

q_a: quick_sort_i.c
    gcc -o q_a quick_sort_i.c

With that, make will recompile q_a if necessary.

Barnie answered 15/2, 2014 at 8:27 Comment(4)
I still have the same problem. I tried even this: q_a: quick_sort_i.o || gcc -o q_a quick_sort_i.o || quick_sort_i.o: quick_sort_i.c || gcc -o quick_sort_i.c -c || and i have the same problem too. Any other suggestion?Mm
@a_user: it seems that you have a file q_a in the directory you are buildng in. If not, double check that the rules in your makefile are indented with tabs, if none of these help, try touch quick_sort_i.c and run make again. at least one of these should work.Barnie
@a_user: yes, if you only run make it will by default run the first rule of your makefile. if you need all targets to be built, add a target at the top like all: q_a q_g s_a s_g forkBarnie
@Mm yes, see my comment above :)Barnie
S
0

is not actually an error; it indicates that the target mpi_wavefront has already been built and there are no changes that require rebuilding the target. Essentially, make believes that the compiled output is up to date with respect to the source file mpi_wavefront.cpp.

make clean make mpi_wavefront

Subtonic answered 1/10, 2024 at 21:1 Comment(1)
That command will attempt to build the clean, make, and mpi_wavefront targets, none of which exist in that makefile. And there is no mpi_wavefront.cpp mentioned, either. Did you post this answer on the wrong question or something?Barony

© 2022 - 2025 — McMap. All rights reserved.