当前位置:网站首页>第一次使用gcc和makefile编写c程序
第一次使用gcc和makefile编写c程序
2022-06-28 01:03:00 【m0_61811389】
一、用gcc编写一个主函数main.c和子程序sub.c
1.编写一个主函数main.c
#include"stdio.h"
float x2x(int a,int b);
int main()
{
int x=2,y=4; //定义x和y变量
printf("%.2f\n",x2x(x,y));
return 0;
}2.编写一个子函数sub.c
float x2x(int a,int b)
{
float c;
c=a+b;
return c;
}3.运行程序
4.windows用dev c++编写
sub.h
#include"stdio.h"
float x2x(int a,int b)
{
float c;
c=a+b;
return c;
}main.c
#include"stdio.h"
#include"sub.h"
float x2x(int a,int b);
int main(){
int x=2,y=4;
printf("%.2f\n", x2x(x,y));
return 0;
}运行程序

二、用Makefile编写
1.Makefile的编写规则
target:prerequisites
command # command以一个tab键开始
# target为一个目标文件,可以是Object File,也可以是执行文件。还可以是一个标签(Label)
# prerequisites是需要生成target所依赖的文件或是目标
# command也就是make需要执行的命令。(任意的Shell命令)
2.编写makefile文件
main:sub.o main.c
gcc main.c sub.o -o main
sub.o:sub.c
gcc -c sub.c -o sub.o
clean:
rm *.o注意用tab键开始!
3.使用makefile编译c程序

4.在源文件目录下执行命令make clean,即可删除编译过程中产生的*.o文件

5.运行结果

总结
Make和makefile可以完成对于多个文件的维护工作,Make和makefile的关系:make是一个命令工具,是一个解释makefile中指令的命令工具,一般来说,大多数的IDE都有这个命令.
边栏推荐
- Unity WebGL打包后怎么运行(火狐配置)
- MFC common current path
- 【历史上的今天】6 月 24 日:网易成立;首届消费电子展召开;世界上第一次网络直播
- 横向滚动的RecycleView一屏显示五个半,低于五个平均分布
- How to realize red, green and yellow traffic lights in ros+gazebo?
- JS实现滑动拼图验证
- Différences d'utilisation entre IsEmpty et isblank
- Mysql数据库基础:DML数据操作语言
- 【历史上的今天】6 月 19 日:iPhone 3GS 上市;帕斯卡诞生;《反恐精英》开始测试
- Character interception triplets of data warehouse: substrb, substr, substring
猜你喜欢

如何判断线程池已经执行完所有任务了?

英特尔锐炫A380显卡即将在中国面市

在线JSON转PlainText工具

迪赛智慧数——柱状图(折柱混合图):2021年毕业季租房价格和房租收入比

Opencv -- Hough transform and some problems encountered

云原生(三十) | Kubernetes篇之应用商店-Helm

Data governance and data standards

Exploration on the construction path of real-time digital warehouse integrating digital intelligence learning and streaming batch

NER中BiLSTM-CRF解读Forward_algorithm

【历史上的今天】6 月 2 日:苹果推出了 Swift 编程语言;电信收购联通 C 网;OS X Yosemite 发布
随机推荐
Data governance and data standards
Win11不能拖拽图片到任务栏软件上快速打开怎么办
Graduation summary
【电梯控制系统】基于VHDL语言和状态机实现的电梯控制系统的设计,使用了状态机
把腾讯搬上云:云服务器 CVM 的半部进化史
[today in history] June 2: Apple launched swift programming language; China Telecom acquires China Unicom C network; OS X Yosemite release
【历史上的今天】6 月 24 日:网易成立;首届消费电子展召开;世界上第一次网络直播
【历史上的今天】6 月 6 日:世界 IPv6 启动纪念日;《俄罗斯方块》发布;小红书成立
ROS+Gazebo中红绿黄交通灯如何实现?
Design e-commerce seckill system
[today in history] June 11: the co inventor of Monte Carlo method was born; Google launched Google Earth; Google acquires waze
迪赛智慧数——柱状图(折柱混合图):2021年毕业季租房价格和房租收入比
设计电商秒杀系统
Practice of low code DSL in data warehouse
在线JSON转PlainText工具
What if win11 can't drag an image to the taskbar software to open it quickly
StaticLayout的使用详解
畢業總結
Leetcode topic [array] -228- summary interval
【历史上的今天】6 月 5 日:洛夫莱斯和巴贝奇相遇;公钥密码学先驱诞生;函数语言设计先驱出生
