一.编写主程序文件main1.c
输入gedit.c打开main1.c文件进行编辑
代码如下:
#include<stdio.h>
float x2x(int a,int b);
int main()
{
int a;
int b;
printf("please input a:");
scanf("%d",&a);
printf("please input b:");
scanf("%d",&b);
printf("%.2f",x2x(a,b));
return 0;
}
二.创建子程序sub1.c
代码如下:
#include<studio.h>
float x2x(int a,int b)
{
float c;
c=a+b;
return c;
}
三.运行结果
gcc命令行:
windows下:
四.Makefile编辑主程序
CC=gcc
objects=scr/main.o scr/sub1.o
target=main
$(target):$(objects)
$(CC) -o $(target) $(objects)
scr/main.o:scr/main.c
$(CC) -o $@ -c $<
scr/sub1.o:scr/sub1.c
$(CC) -o $@ -c $<
clean:
rm -rf $(objects) $(target)