码迷,mamicode.com
首页 > 其他好文 > 详细

如何编写Makefile?

时间:2015-04-02 20:32:10      阅读:112      评论:0      收藏:0      [点我收藏+]

标签:

//swap.c
#include<stdio.h>
int swap(int *x,int *y)
{printf("a=%d b=%d\n",*x,*y);
 int z;
 z=*x;
 *x=*y;
 *y=z;
 printf("a=%d b=%d\n",*x,*y);
}
//max.c
int max(int a,int b)
{
 return a>b?a:b;
}
//test.c
int main()
{
  int x=3,y=4;
  printf("max=%d\n",max(x,y));
  swap(&x,&y);
 }
技术分享
下来我们来编写Makefile文件
vi Makefile //文件名一定要为Makefile,不能是其他任何名字,标准为Makefile,书上写的是makefile
all:test
max.o:max.c
    gcc -o max.o -c max.c
swap.o:swap.c
    gcc -o swap.o -c swap.c
test.o:test.c
    gcc -o test.o -c test.c
test:max.o swap.o test.o
    gcc -o test swap.o max.o test.o

技术分享
编写Makefile时,最好用vi编辑器,不可用记事本gedit,否则会出现如下错误的!!!!
技术分享

 

如何编写Makefile?

标签:

原文地址:http://www.cnblogs.com/leijiangtao/p/4388208.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!