当前位置:网站首页>第一次使用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都有这个命令.
边栏推荐
- Win11 ne peut pas faire glisser l'image sur le logiciel de la barre des tâches
- MySQL优化小技巧
- 【历史上的今天】6 月 23 日:图灵诞生日;互联网奠基人出生;Reddit 上线
- [today in history] June 11: the co inventor of Monte Carlo method was born; Google launched Google Earth; Google acquires waze
- Livedata interview question bank and answers -- 7 consecutive questions for livedata interview~
- math_(函数&数列)极限的含义&误区和符号梳理/邻域&去心邻域&邻域半径
- Redis~geospatial (geospatial), hyperloglog (cardinality Statistics)
- Keil "St link USB communication error" solution
- 【二維碼圖像矯正增强】基於MATLAB的二維碼圖像矯正增强處理仿真
- [today in history] June 8: the father of the world wide web was born; PHP public release; IPhone 4 comes out
猜你喜欢
Flask基础:模板渲染+模板过滤使用+控制语句
Design e-commerce seckill system
How does win11 close recently opened projects? Win11 method to close recently opened projects
[today in history] May 29: the pioneer of sharing software was born; Chromebox launched; VoodooPC founder was born
【历史上的今天】6 月 20 日:MP3 之父出生;富士通成立;谷歌收购 Dropcam
【历史上的今天】6 月 19 日:iPhone 3GS 上市;帕斯卡诞生;《反恐精英》开始测试
被通知裁员后拿到5个offer
在线JSON转PlainText工具
Win11无法使用动态壁纸怎么办?Win11用不了动态壁纸的解决方法
Opencv -- Hough transform and some problems encountered
随机推荐
Win11新建不了文本文档?Win11右键无法新建文本文档的解决方法
Moving Tencent to the cloud: half of the evolution history of cloud server CVM
【历史上的今天】6 月 23 日:图灵诞生日;互联网奠基人出生;Reddit 上线
[cloud native] - docker installation and deployment of distributed database oceanbase
[today in history] June 6: World IPv6 launch anniversary; Tetris release; Little red book established
Stm32f1 interrupt introduction
【倒立摆控制】基于UKF无迹卡尔曼滤波的倒立摆控制simulink仿真
【历史上的今天】6 月 12 日:美国进入数字化电视时代;Mozilla 的最初开发者出生;3Com 和美国机器人公司合并
Teach you how to realize pynq-z2 bar code recognition
榜单首发——前装搭载率站上10%大关,数字钥匙方案供应商TOP10
Shardingsphere-proxy-5.0.0 establish MySQL read / write separation connection (6)
JS implementation of Slide Puzzle verification
【历史上的今天】6 月 7 日:Kubernetes 开源版本发布;《魔兽世界》登陆中国;分组交换网络发明者出生
数智学习|湖仓一体实践与探索
【历史上的今天】6 月 16 日:甲骨文成立;微软 MSX 诞生;快速傅里叶变换发明者出生
【历史上的今天】6 月 24 日:网易成立;首届消费电子展召开;世界上第一次网络直播
STM32F1与STM32CubeIDE编程实例-金属触摸传感器驱动
如何系统学习LabVIEW?
Opencv -- Hough transform and some problems encountered
How to systematically learn LabVIEW?