Linux下编译C程序

act.c文件
#include <stdio.h>
#include "a.h"
int main(){
printf("start%d\n",add(1,200));
print();
return 0;
}
a.c文件

1
#include <stdio.h>
2 #include <stdlib.h>
3 #include <stdarg.h>
4 #include <setjmp.h>
5 #include "a.h"
6 jmp_buf buf;
7 int add(int a,int b){
8 if(a<100)
9 ERROR(-1,"错误 a:%d 小于100",a);
10 if(b<100)
11 ERROR(-1,"错误 b:%d 小于100",b);
12 return a+b;
13 }
14
15 void print(){
16 int c =10;
17 printf("c=%d\n",c);
18 if(!setjmp(buf)){
19 printf("c=%d\n",c);
20 c = add(2,2);
21 printf("c=%d\n",c);
22 longjmp(buf,1);
23 }
24 else{
25 printf("c=%d\n",c);
26 }
27
28 }
29 int logging(int code,char fmt[],...){
30 va_list l;
31 FILE *fp;
32 if( (fp=fopen("err.log","w"))==NULL ){
33 printf("error\n");
34 exit(0);
35 }
36 va_start(l,fmt);
37 vfprintf(fp,fmt,l);
38 fclose(fp);
39 va_end(l);
40 return code;
41 }

Makefile
act:act.o a.o
cc -o act act.o a.o
act.o:act.c
cc -c act.c
a.o:a.c
cc -c a.c
clean:
rm act.o a.o


posted @ 2011-12-13 11:01  夜流冰love伊雪  阅读(217)  评论(0)    收藏  举报