当前位置:网站首页>Writing C program with GCC and makefile for the first time
Writing C program with GCC and makefile for the first time
2022-06-28 02:49:00 【m0_ sixty-one million eight hundred and eleven thousand three h】
List of articles
One 、 use gcc Write a main function main.c And subroutines sub.c
1. Write a main function main.c
#include"stdio.h"
float x2x(int a,int b);
int main()
{
int x=2,y=4; // Definition x and y Variable
printf("%.2f\n",x2x(x,y));
return 0;
}2. Write a sub function sub.c
float x2x(int a,int b)
{
float c;
c=a+b;
return c;
}3. Run the program
4.windows use dev c++ To write
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;
}Run the program

Two 、 use Makefile To write
1.Makefile Rules for writing
target:prerequisites
command # command With a tab Key start
# target For a target file , It can be Object File, It can also be an execution file . It can also be a label (Label)
# prerequisites It needs to be generated target Depending on the file or target
# command That is to say make Commands that need to be executed .( Any of the Shell command )
2. To write makefile file
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 *.oUse it carefully tab Key start !
3. Use makefile compile c Program

4. Execute the command in the source file directory make clean, You can delete the *.o file

5. Running results

summary
Make and makefile You can maintain multiple files ,Make and makefile The relationship between :make It's a command tool , It's an explanation makefile The command tool of the command in , Generally speaking , Most of the IDE There's an order to .
reference :Ubuntu System use gcc and Makefile compile C Program _ No # once & Listening blog -CSDN Blog
Ubuntu16.04 Next C Language compilation and makefile Application - lee_24 - Blog Garden
边栏推荐
- 数智学习 | 流批一体实时数仓建设路径探索
- Résumé de la graduation
- 迪赛智慧数——柱状图(折柱混合图):2021年毕业季租房价格和房租收入比
- Interview: how do lists duplicate objects according to their attributes?
- JS implementation of Slide Puzzle verification
- Starting sequence of Turing machine
- What if win11 can't drag an image to the taskbar software to open it quickly
- math_(函数&数列)极限的含义&误区和符号梳理/邻域&去心邻域&邻域半径
- STM32的C语言与汇编语言混合编程
- [today in history] June 5: Lovelace and Babbage met; The pioneer of public key cryptography was born; Functional language design pioneer born
猜你喜欢

Win11 ne peut pas faire glisser l'image sur le logiciel de la barre des tâches

【方块编码】基于matlab的图像方块编码仿真

树莓派-环境设置和交叉编译

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

【历史上的今天】6 月 15 日:第一个手机病毒;AI 巨匠司马贺诞生;Chromebook 发布

【历史上的今天】5 月 31 日:Amiga 之父诞生;BASIC 语言的共同开发者出生;黑莓 BBM 停运

Digital intelligence learning Lake Warehouse Integration Practice and exploration

Stm32f1 and stm32subeide programming example - metal touch sensor driver

MySQL optimization tips

在线JSON转PlainText工具
随机推荐
NER中BiLSTM-CRF解读Forward_algorithm
Flashtext, a data cleaning tool, has directly increased the efficiency by dozens of times
【方块编码】基于matlab的图像方块编码仿真
Interview: is bitmap pixel memory allocated in heap memory or native
初始线性回归
JS implementation of Slide Puzzle verification
> Could not create task ‘:app:MyTest. main()‘. > SourceSet with name ‘main‘ not found. Problem repair
【历史上的今天】6 月 16 日:甲骨文成立;微软 MSX 诞生;快速傅里叶变换发明者出生
How to realize red, green and yellow traffic lights in ros+gazebo?
树莓派-环境设置和交叉编译
Design e-commerce seckill system
Cloud native (30) | kubernetes' app store Helm
The first place on the list - the carrying rate of front-end equipment is up to 10%, and the top 10 suppliers of digital key solutions
Win11不能拖拽圖片到任務欄軟件上快速打開怎麼辦
【历史上的今天】6 月 13 日:分组交换网路的“亲子纠纷”;博弈论创始人出生;交互式电视初现雏形
简单ELK配置实现生产级别的日志采集和查询实践
【历史上的今天】6 月 12 日:美国进入数字化电视时代;Mozilla 的最初开发者出生;3Com 和美国机器人公司合并
[fuzzy neural network] simulation of fuzzy neural network based on MATLAB
[block coding] simulation of image block coding based on MATLAB
Digital intelligence learning Lake Warehouse Integration Practice and exploration
