文件add.h
#ifndef ADD_H_
#define ADD_H_
int add(int,int);
double add2(double,double);
#endif
文件add.c
int add(int a,int b){
return a+b;
}
double add2(double a,double b){
return a+b;
}
文件test.c
#include <stdio.h>
#include "add.h"
int main(){
int r1 = add(2,3);
double r2 = add2(3.0,2.0);
printf("r1=%d,r2=%lf\n",r1,r2);
return 0;
}
gcc test.c add.c –I <指定路径>命令一次性编译链接源文件test.c和add.c,
由于没有指定生成的文件名,所以生成可执行文件a.out。
#ifndef ADD_H_
#define ADD_H_
int add(int,int);
double add2(double,double);
#endif
文件add.c
int add(int a,int b){
return a+b;
}
double add2(double a,double b){
return a+b;
}
文件test.c
#include <stdio.h>
#include "add.h"
int main(){
int r1 = add(2,3);
double r2 = add2(3.0,2.0);
printf("r1=%d,r2=%lf\n",r1,r2);
return 0;
}
gcc test.c add.c –I <指定路径>命令一次性编译链接源文件test.c和add.c,
由于没有指定生成的文件名,所以生成可执行文件a.out。