makefile for Linux纯小白版
2024-08-24 12:09:15
某大佬曾说过:
不会makefile,不要说你会linux,因为makefile是合格程序员的必经之路
首先你要有个vi或者emacs 之类的编辑器
编写几个程序
test1.c
#include<stdio.h>
#include "test2.h" int main()
{
printf("This is test1!\n");
PrintTest2();
return ;
}
test2.c
#include<stdio.h>
#include "test2.h" int main()
{
printf("This is test1!\n");
PrintTest2();
return ;
}
test2.h:
#ifndef TEST2_H_
#define TEST2_H_ void PrintTest2(); #endif
然后你的makefile
需要建立一个文件叫makefile(可以是MAKEFILE)-------但是只能是这两个名字
接下来就是makefile中的内容
test: test1.o test2.o //这是主要的文件,后面两个是形成的执行文件
gcc -Wall test1.o test2.o -o test test1.o: test1.c test2.h//底下这些就是每一个执行文件所包含的.c .h文件
gcc -c -Wall test1.c -o test1.o//编译 test2.o: test2.c test2.h//执行文件所包含的.c .h文件
gcc -c -Wall test2.c -o test2.o clean: //删除
rm -rf *.o test
运行的时候是
./test
可以用"代号":使用变量
前几行是声明
varname = xxx
底下写的时候就直接用就行
使用的时候要$(varname)
OBJS = test1.o test2.o
G = gcc
CFLAGS = -Wall -O -g test:$(OBJS)
$(G) $(OBJS) -o test test1.o:test1.c test2.h
$(G) $(CFLAGS) -c test1.c
test2.o:test2.c test2.h
$(G) $(CFLAGS) -c test2.c clean:
rm -rf *.o test
makefile加油呀!
最新文章
- 关于SilverLight
- angularjs 自带的过滤器
- http://www.cnblogs.com/younggun/archive/2013/07/16/3193800.html
- Effective C++ 沉思录
- HTTP基本协议(查看网页代码)
- (Python3) 连加 连乘 代码
- vue-lazyload懒加载插件的使用
- CSS中清除浮动的作用以及如何清除浮动
- TCP/UDP 协议
- SAP 从数据库中查询数据,带有where 条件。
- springMVC学习 七 视图解析器
- HDU 2066 一个人的旅行 最短路问题
- R语言 如何用IF语句判断 一个数字的奇偶
- ZOJ 3946.Highway Project(The 13th Zhejiang Provincial Collegiate Programming Contest.K) SPFA
- apicloud管理
- jdbc批处理
- (转) bicabo Visual Studio 2012自动添加注释(如版权信息等)
- IEnumerable<;T>; 接口和GetEnumerator 详解
- 浅谈iOS学习之路(转)
- SSH笔记一
热门文章
- mysql根据一张表更新另一张表数据
- 查看笔记本SN序列号
- Data types &#39;int&#39; and &#39;float&#39;
- 进阿里真的这么难?P8大佬告诉你,你和阿里之间缺的只是这份笔记
- Rust String(官方文档翻译)
- EntityFrameworkCore 开发实践问题及规范
- Dynamics CRM Data Encrytion error
- Python之协程、异步IO、redis缓存、rabbitMQ队列
- 关于springboot中过滤器和拦截器
- easyui datagrid 中添加combobox