Makefile of Multiple folders

Source: Internet
Author: User

 

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.