一、ubuntu使用gcc
- 创建sub1.c子程序
#include <stdio.h>
float x2x(int a, int b)
{
float c;
c = a + b;
return c;
}
- 创建main1.c主程序
#include <stdio.h>
#include "sub1.c"
int main()
{
int a = 3, b = 5;
float c;
float x2x(int a, int b);
c = x2x(a, b);
printf("%f\n", c);
return 0;
}
- 进入ubuntu终端,建立文件夹test,并将main1.c与sub1.c装入其中
mkdir test
cd test
6. 用gcc运行main1.c
gcc main.c -o main.o
./main1.o
二、ubuntu使用makefile
- 编写makefile
- 运行makefile