当前位置:网站首页>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
边栏推荐
- [JS reverse hundreds of examples] I love to solve 2022 Spring Festival problems and receive red envelopes
- Win11如何关闭最近打开项目?Win11关闭最近打开项目的方法
- Win11不能拖拽圖片到任務欄軟件上快速打開怎麼辦
- 字节跳动面试官:一张图片占据的内存大小是如何计算
- isEmpty 和 isBlank 的用法區別
- Redis~geospatial (geospatial), hyperloglog (cardinality Statistics)
- Moving Tencent to the cloud: half of the evolution history of cloud server CVM
- 初始线性回归
- 【历史上的今天】6 月 12 日:美国进入数字化电视时代;Mozilla 的最初开发者出生;3Com 和美国机器人公司合并
- How to run unity webgl after packaging (Firefox configuration)
猜你喜欢

How does win11 add printers and scanners? Win11 add printer and scanner settings

Skills in schematic merging

数智学习 | 流批一体实时数仓建设路径探索
![[today in history] June 6: World IPv6 launch anniversary; Tetris release; Little red book established](/img/06/895913d2c54b03cde86b3116955a9e.png)
[today in history] June 6: World IPv6 launch anniversary; Tetris release; Little red book established

Teach you how to realize pynq-z2 bar code recognition

StaticLayout的使用详解

STM32的C语言与汇编语言混合编程

Win11新建不了文本文档?Win11右键无法新建文本文档的解决方法

From how to use to how to implement a promise

【历史上的今天】6 月 20 日:MP3 之父出生;富士通成立;谷歌收购 Dropcam
随机推荐
【历史上的今天】6 月 19 日:iPhone 3GS 上市;帕斯卡诞生;《反恐精英》开始测试
Moving Tencent to the cloud: half of the evolution history of cloud server CVM
如何开启多语言文本建议?Win11打开多语言文本建议的方法
How to enable multi language text suggestions? Win11 method to open multilingual text suggestions
[today in history] June 8: the father of the world wide web was born; PHP public release; IPhone 4 comes out
Architecture high reliability application knowledge map ----- microservice architecture map
JS implementation of Slide Puzzle verification
启牛开户安全吗?怎么线上开户?
MFC CString互转LPVOID
[today in history] June 3: Microsoft launched Bing search engine; Larry Roberts starts ARPANET; The father of Visual Basic was born
【历史上的今天】6 月 8 日:万维网之父诞生;PHP 公开发布;iPhone 4 问世
Interpretation of the source code of scheduledthreadpoolexecutor (II)
[today in history] June 11: the co inventor of Monte Carlo method was born; Google launched Google Earth; Google acquires waze
Différences d'utilisation entre IsEmpty et isblank
毕业总结
math_ (function & sequence) meaning of limit & misunderstanding and symbol sorting / neighborhood & de centring neighborhood & neighborhood radius
Win11新建不了文本文档?Win11右键无法新建文本文档的解决方法
High reliability application knowledge map of Architecture -- the path of architecture evolution
《天天数学》连载53:二月二十一日
NER中BiLSTM-CRF解读Forward_algorithm
