Ubuntu系统下分别用gcc和Makefile方式编译C程序

目录

(一)用gcc命令行方式编译主程序

1.编写c程序

2.通过gcc编译

3.用Windows编译工具编译main.c并进行对比

(二) 用Makefile方式编译主程序

1.编写Makefile文件

2.使用Makefile文件编译c程序

(一)用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:

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值