Tutorials Point


  Makefile Tutorial
  Selected Reading

© 2011 TutorialsPoint.COM


  Home     References     About TP     Advertising  

Defining Dependencies in Makefile

previous next AddThis Social Bookmark Button


It is very common that a final binary will be dependent on various source code and source header files. Dependencies are important because they tell to make about the source for any target. Consider the following example

hello: main.o factorial.o hello.o
	$(CC) main.o factorial.o hello.o -o hello

Here we are telling to make that hello is dependent on main.o, factorial.o and hello.o so whenever there is a change in any of these object files then make will take action.

Same time we would have to tell to make how to prepare .o files so we would have to define those dependencies also as follows
main.o: main.cpp functions.h
	$(CC) -c main.cpp

factorial.o: factorial.cpp functions.h
	$(CC) -c factorial.cpp

hello.o: hello.cpp functions.h
	$(CC) -c hello.cpp



previous next Printer Friendly



  

Advertisement

Online Image Processing

Indian Baby Names