//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,否则会出现如下错误的!!!!
时间: 2024-10-05 18:11:37