Linux Study Notes 6. makefile file manager and makefile file creation
Source: Internet
Author: User
Linux study note 6. makefile file manager and makefile file creation-Linux general technology-Linux programming and kernel information. For details, see the following. Splitting source program files is conducive to developing large programs and improving the efficiency of programming. But the more files are separated, the more compilation and Maintenance
Difficult. To prevent changes to one or more files in a project, you do not need to recompile the entire project. Make Project
The manager is an "automatic compiler", where "automatic" refers to the ability to automatically discover updated files according to the file time and subtract
Small compilation workload. At the same time, it reads the contents of makefile to execute a lot of compilation work. You only need to write a simple
Compile the statement.
Makefile files include:
1). the target object (target) created by the make tool is required, usually the target file or executable file.
2). the object to be created depends on
3). commands to be run when creating each target body
For example, a program is designed to calculate the total and average scores of students and compile the program with the make project manager.
Step 1
Program: 1. # include
# Include "chengji. h"
Int main ()
{
Int n, I;
Float average, sum;
Scanf ("% d", & n );
Int array [n];
For (I = 0; I <= n; I ++)
{
Printf ("Please input the % dth student's score :");
Scanf ("% d", & arrary
); } Sum = fun_sum (array, n);/* call fun_sum function */ Printf ("the all students scores is: % d", sum ); Average = fun_avg (array, n);/* call fun_avg function, return avg's value */ Printf ("the average is:", average ); }
2./* chengji. h is a head file, include the statement of fun_avg and fun_sum */ Float fun_sum (int var [], int num ); Float fun_avg (int var [], int num );
3./* fun_sum.c is fun_sum's difinition */ Float fun_sum (int var [], int num) { Float avrg = 0.0; Int I; For (I = 0; I Avrg + = var; Return (avrg ); }
4. float fun_avg (int var [], int num) { Float avrg = 0.0; Int I; For (I = 0; I Avrg + = var; Avrg/= num; Return (avrg ); }
Step 2 Use the text file editor to edit the makefile file. The editing procedure is as follows: [...] # Vi makefile1_1 2-5:2-5-main.o 2-5-fun_sum.o 2-5-fun_avg.o Gcc 2-5-main.o 2-5-fun_sum.o 2-5-fun_avg.o-o 2-5 2-5.main.o: 2-5-main.c chengji. h Gcc 2-5-main.c-c 2-5-fun_sum.o: 2-5-fun_sum.c Gcc 2-5-fun_sum.c-c 2-5-fun_avg.o: 2-5-fun_avg.c Gcc 2-5-fun_avg.c-c
Note: make Target file: Dependent File (Tab) command to generate the target file
Step 3 Use make to compile makefile files [...] # Make-f makefile1_1
Step 4 If a file is modified, only the modified files will be compiled again.
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.