当前位置:网站首页>第一次使用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都有这个命令.
边栏推荐
- js实现时钟
- Win11 cannot create a new text document? Solution to win11 right click failure to create a new text document
- [today in history] June 2: Apple launched swift programming language; China Telecom acquires China Unicom C network; OS X Yosemite release
- CRF+BiLSTM代码分步骤解读
- Practice of low code DSL in data warehouse
- Data governance and data standards
- Prometheus 2.27.0 新特性
- Mysql数据库基础:DML数据操作语言
- isEmpty 和 isBlank 的用法區別
- 【历史上的今天】6 月 18 日:京东诞生;网店平台 Etsy 成立;Facebook 发布 Libra 白皮书
猜你喜欢

【倒立摆控制】基于UKF无迹卡尔曼滤波的倒立摆控制simulink仿真

Win11如何关闭最近打开项目?Win11关闭最近打开项目的方法
![[today in history] June 1: Napster was founded; MS-DOS original author was born; Google sells Google SketchUp](/img/fe/497eab2ac4a762298e71d28ed26e41.png)
[today in history] June 1: Napster was founded; MS-DOS original author was born; Google sells Google SketchUp
![[cloud native] - docker installation and deployment of distributed database oceanbase](/img/02/57ab785acafd8ff0a49c584dd05188.png)
[cloud native] - docker installation and deployment of distributed database oceanbase

Data governance and data standards

High reliability application knowledge map of Architecture -- the path of architecture evolution

Starting sequence of Turing machine

What if win11 can't drag an image to the taskbar software to open it quickly

Low code solution - a low code solution for digital after-sales service covering the whole process of work order, maintenance and Finance

如何判断线程池已经执行完所有任务了?
随机推荐
How to use data-driven "customer lifecycle management" to improve lead conversion rate and customer satisfaction?
Résumé de la graduation
【历史上的今天】6 月 18 日:京东诞生;网店平台 Etsy 成立;Facebook 发布 Libra 白皮书
【历史上的今天】6 月 16 日:甲骨文成立;微软 MSX 诞生;快速傅里叶变换发明者出生
【历史上的今天】6 月 20 日:MP3 之父出生;富士通成立;谷歌收购 Dropcam
【历史上的今天】6 月 23 日:图灵诞生日;互联网奠基人出生;Reddit 上线
畢業總結
[cloud native] - docker installation and deployment of distributed database oceanbase
【历史上的今天】6 月 5 日:洛夫莱斯和巴贝奇相遇;公钥密码学先驱诞生;函数语言设计先驱出生
【历史上的今天】6 月 13 日:分组交换网路的“亲子纠纷”;博弈论创始人出生;交互式电视初现雏形
Design e-commerce seckill system
【历史上的今天】6 月 2 日:苹果推出了 Swift 编程语言;电信收购联通 C 网;OS X Yosemite 发布
Data governance and data standards
Mysql大合集,你要内容的这里全都有
【 amélioration de la correction d'image de Code bidimensionnel】 simulation du traitement d'amélioration de la correction d'image de Code bidimensionnel basée sur MATLAB
SQL reported an unusual error, which confused the new interns
Usage differences between isempty and isblank
Opencv -- Hough transform and some problems encountered
【方块编码】基于matlab的图像方块编码仿真
数仓的字符截取三胞胎:substrb、substr、substring
