makefile Functions of makefile Common error

reference

  • replace repetition of linking
  • gcc *.c -o prog
  • quick compiling time (prev way is 1 for everytime so that’s O(n))

Functions of makefile

  • build
  • link

build

write inside makefile

1
2
prog:
t gcc a.o b.o c.o -o prog

terminal make reports no change when changes occur

update/rebuild

1
2
3
4
5
6
7
prog: a.o b.o c.o
t gcc a.o b.o c.o -o prog
a.o: a.c #adding filename after specified output file
t gcc a.c -o a.o -c
b.o: b.c
t gcc b.c -o b.o -c

parallel option

adding -jn n=num of buildtasks
eg make -j4 #means compile 4 tasks

makefile can be used as parallel execution as well

Common error

Makefile:2: *** missing separator. Stop.
solution is to check for tabs