目录
(一)用gcc命令行方式编译主程序
1.编写c程序
•编写主程序文件main.c
#include "sub1.h"
int main()
{
int x=3,y=4; //定义a,b变量
printf("%.2f\n",x2x(x,y)); //保留两位小数输出结果
return 0;
}
•编写sub1.h
#ifndef _sub1_h
#define _sub1_h
#include<stdio.h>
#include<math.h>
float x2x(int a, int b);
#endif
•编写子程序sub1.c
#include "sub1.h"
float x2x(int a,int b)
{
float ans; //返回值
ans=float(a/b);
return ans;
}
2.通过gcc编译
•将sub1.c程序转换为目标文件sub1.o: