Chinaunix首页 | 论坛 | 博客
  • 博客访问: 188626
  • 博文数量: 26
  • 博客积分: 2031
  • 博客等级: 大尉
  • 技术积分: 180
  • 用 户 组: 普通用户
  • 注册时间: 2009-10-10 22:13
文章分类

全部博文(26)

文章存档

2015年(1)

2013年(1)

2012年(1)

2011年(1)

2010年(17)

2009年(5)

我的朋友

分类:

2009-10-22 22:16:57

假设我们有一个程序由5个文件组成,源代码如下:
/*main.c*/
#include "mytool1.h"
#include "mytool2.h"
int main()
{
         mytool1_print("hello mytool1!");
         mytool2_print("hello mytool2!");
        return 0;
}
 
/*mytool1.c*/
#include "mytool1.h"
#include stdio.h>
void mytool1_print(char *print_str)
{
         printf("This is mytool1 print : %s ",print_str);
}
/*mytool1.h*/
#ifndef _MYTOOL_1_H
#define _MYTOOL_1_H
        void mytool1_print(char *print_str);
#endif
/*mytool2.c*/
#include "mytool2.h"
#include stdio.h>
void mytool2_print(char *print_str)
{
         printf("This is mytool2 print : %s ",print_str);
}
/*mytool2.h*/
#ifndef _MYTOOL_2_H
#define _MYTOOL_2_H
        void mytool2_print(char *print_str);
#endif
    首先了解一下make和Makefile。GNU make是一个工程管理器,它可以管理较多的文件。我所使用的RedHat
9.0的make版本为GNU Make version
3.79.1。使用make的最大好处就是实现了“自动化编译”。如果有一个上百个文件的代码构成的项目,其中一个或者几个文件进行了修改,make就能
够自动识别更新了的文件代码,不需要输入冗长的命令行就可以完成最后的编译工作。make执行时,自动寻找Makefile(makefile)文件,然
后执行编译工作。所以我们需要编写Makefile文件,这样可以提高实际项目的工作效率。
    在一个Makefile中通常包含下面内容:
1、需要由make工具创建的目标体(target),通常是目标文件或可执行文件。
2、要创建的目标体所依赖的文件(dependency_file)。
3、创建每个目标体时需要运行的命令(command)。
格式如下:
target:dependency_files
TAB>command
target:规则的目标。通常是程序中间或者最后需要生成的文件名,可以是.o文件、也可以是最后的可执行程序……
阅读(881) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~