Makefile 教程
来源:互联网 发布:pubmed数据库主题词 编辑:程序博客网 时间:2024/04/27 13:34
Makefile 教程
一、先来个简单实用的入门实例
两个源文件 helloworld.c 和 test.c :
$ ls
helloworld.c test.c
源代码:
1. 编写 Makefile 文件
在源文件目录下编写Makefile文件,内容如下:
test: test.c helloworld.c
@gcc $^ -o $@
.PHONY : clean
clean :
@rm -f test *.o
$^:代表所有依赖文件
$@:代表目标
保存文件,目录内容:
$ ls
helloworld.c Makefile test.c
2. 执行 make 编译源代码
$ make
$ ls
helloworld.c Makefile test test.c
生成了可执行文件test。
3. 运行
$ ./test
Hello World.
结果正确。
4. 执行 make clean 删除编译生成的目标文件
$ ls
helloworld.c Makefile test test.c
$ make clean
$ ls
helloworld.c Makefile test.c
删除了test。
一、先来个简单实用的入门实例
两个源文件 helloworld.c 和 test.c :
$ ls
helloworld.c test.c
源代码:
helloworld.c
#include<stdio.h>void printHelloWorld(){printf("Hello World.\n");return;}test.c
#include<stdio.h>extern printHelloWorld();void main(){printHelloWorld();return;}
1. 编写 Makefile 文件
在源文件目录下编写Makefile文件,内容如下:
test: test.c helloworld.c
@gcc $^ -o $@
.PHONY : clean
clean :
@rm -f test *.o
注意:第2行和第5行前要打个 [Tab] 键。
【说明】$^:代表所有依赖文件
$@:代表目标
.PHONY:指名一个目标是伪目标
伪目标clean把编译生成的可执行文件test和.o文件删除。
保存文件,目录内容:
$ ls
helloworld.c Makefile test.c
2. 执行 make 编译源代码
$ make
$ ls
helloworld.c Makefile test test.c
生成了可执行文件test。
3. 运行
$ ./test
Hello World.
结果正确。
4. 执行 make clean 删除编译生成的目标文件
$ ls
helloworld.c Makefile test test.c
$ make clean
$ ls
helloworld.c Makefile test.c
删除了test。
0 0
- Makefile教程
- Makefile教程
- Makefile教程
- makefile教程
- makefile教程
- Makefile教程
- makefile教程
- makefile教程
- makefile教程
- makefile教程
- Makefile教程
- Makefile教程
- makefile教程
- makefile 教程
- makefile教程
- makefile教程
- makefile教程
- Makefile教程
- Java参数传值详解
- 0/1背包问题
- Python的sys.stdout、sys.stdin重定向
- iOS APP多语言开发(国际化)
- c++ getline正确读取多行内容
- Makefile 教程
- 全java代码实现Spring与ActiveMQ整合
- linux常用解压压缩命令
- JAVA从一个.p12或.pfx文件中获取公钥和私钥
- (一)linux常用,但容易忘记的命令
- jenkins配置用户名和密码
- 浏览器 HTTP 协议缓存机制详解
- 利用python爬虫大量基金股票的净值写入到csv文件中方便做其他计算
- 游标