You must note that only one main function can be used to compile multiple C programs using makefile.
I want to implement makefile today. It is known that there are two folders, each of which has three C programs, and they are compiled using makefile.
First, create the first src folder and the Third. c file.
Vim guo. c
# Include <stdio. h>
# Include "zhi. h"
# Include "yuan. h"
# Include "/home/feifei/Desktop/text/exit/qian. h"
# Include "/home/feifei/Desktop/text/exit/ru. h"
# Include "/home/feifei/Desktop/text/exit/shi. h"
Void main ()
{
Printf ("guo \ n ");
Zhi ();
Yuan ();
Qian ();
Ru ();
Shi ();
}
Vim zhi. c // omitted
Vim zhi. h
Vim yuan. c
Vim yuan. h
Vim makefile
. PHONY: all
CC = gcc
All: guo. o zhi. o yuan. o
Guo. o: guo. c
$ (CC)-c guo. c
Cp guo. o ../
Zhi. o: zhi. c zhi. h
$ (CC)-c zhi. c
Cp zhi. o ../
Yuan. o: yuan. c yuan. h
$ (CC)-c yuan. c
Cp yuan. o ../
Clean:
Rm-f *. o
Now, the first folder and the content in it are ready. Next we will create the second folder, exit.
(Note that the main function cannot be used for the above functions)
Vim qian. c
# Include <stdio. h>
Void qian ()
{
Printf ("qian \ n ");
}
Vim qian. h
Void qian ();
Vim ru. c // omitted
Vim ru. h
Vim shi. c
Vim shi. h
Vim makefile
. PHONY: obj
CC = gcc
Obj: qian. o ru. o shi. o
Qian. o: qian. c qian. h
$ (CC)-c qian. c
Cp qian. o ../
Ru. o: ru. c ru. h
$ (CC)-c ru. c ru. h
Cp ru. o ../
Shi. o: shi. c shi. h
$ (CC)-c shi. c shi. h
Cp shi. o ../
Clean:
Rm-f *. o
Okay, let's go back to the upper-level directory and write makefile here.
Vim makefile
Feifei: guo. o zhi. o yuan. o qian. o ru. o shi. o
Gcc guo. o zhi. o yuan. o qian. o ru. o shi. o-o feifei
Guo. o:
Cd./src & $ (MAKE)
Zhi. o:
Cd./src & $ (MAKE)
Yuan. o:
Cd./src & $ (MAKE)
Qian. o:
Cd./exit & $ (MAKE)
Ru. o:
Cd./exit & $ (MAKE)
Shi. o:
Cd./exit & $ (MAKE)
Clean:
Rm-r *. o feifei
Then make.
From
Guozhiyuan20095318 Column