0

I have a make file that is not compiling correctly and I can not figure out why. Here is my file:

comp = gcc
comp_flags = -g -Wall 
comp_libs = -lm  
#comp = cc

lab6 : graph_support.o lab6.o
    $(comp) $(comp_flags) graph_support.o lab6.o -o lab6 $(comp_libs)

graph.o : graph_support.c graph.h
    $(comp) $(comp_flags) -c graph_support.c

lab6.o : lab6.c graph.h
    $(comp) $(comp_flags) -c lab6.c

clean :
    rm -f *.o lab6 core

Now here is what happens when I make it:

cc    -c -o graph_support.o graph_support.c
gcc -g -Wall  graph_support.o lab6.o -o lab6 -lm

The second one works correctly but the first one doesnt have the correct comp and comp_flags.

Any reason for this?

1 Answer 1

4

You not tell to make anything about object file graph_support.o, so it decided to compile it with default rules (more information: man make, make -p, gnu docs).

So, you probably need to change graph.o:

graph.o : graph_support.c graph.h
    $(comp) $(comp_flags) -c graph_support.c

to graph_support.o:

graph_support.o : graph_support.c graph.h
    $(comp) $(comp_flags) -c graph_support.c

Usually make used with default (implicit) rules. You can add compile flags to CFLAGS variable (instead of comp_flags) and you will not need rules like

graph_support.o : graph_support.c
...
lab6.o : lab6.c
...
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.