美文网首页Makefile
Makefile的基本使用

Makefile的基本使用

作者: stringlife | 来源:发表于2018-08-10 13:23 被阅读0次

Makefile的基本使用

首先需要有一个Makefile文件
然后执行make即可完成所有的Makefile中定义的符合目标的工作

all:test.c
    gcc test.c -o all
string@asus:~/Projects/makefile$ ls
Makefile  test.c
string@asus:~/Projects/makefile$ make
gcc test.c -o all
string@asus:~/Projects/makefile$ 

接下来完善以下Makefile,增加clean目标、增加test目标,使得Makefile更像一个项目管理的Makefile

all:test

test:test.c
    gcc test.c -o test
clean:
    rm -f test 

此时的Makefile中已经有三个目标
all test clean
其中all依赖于test,test是一个单独的目标,clean是一个单独的目标
这三个目标都可以单独的进行make
make后的效果

string@asus:~/Projects/makefile$ make all
gcc test.c -o test
string@asus:~/Projects/makefile$ make clean 
rm -f test 
string@asus:~/Projects/makefile$ make test 
gcc test.c -o test
string@asus:~/Projects/makefile$

第一步生成all目标,由于all依赖于test,所有重新生成test
第二步清除掉生成test
第三步生成test目标,由于第二步已经清除掉了test目标所以第三步会重新生成test目标

相关文章

  • Linux Kernel Makefiles特殊符号

    Makefile基本规则: Makefile文件中可使用特殊的符号简化Makefile文件的书写。 1、$@:表示...

  • makefile基本使用

    在linux和unix中,有一个强大的实用程序,叫make,可以用它来管理多模块程序的编译和链接,直至生成可执行文...

  • Makefile的基本使用

    Makefile的基本使用 首先需要有一个Makefile文件然后执行make即可完成所有的Makefile中定义...

  • Makefile基础知识

      在Linux下开发,使用Makefile组织源码工程师基本功。在本篇文章中会介绍Makefile的基础知识以及...

  • Makefile学习

    Makefile学习 参考自《跟我一起写Makefile》陈皓 Makefile 的语法规则 基本语法 翻译成中文...

  • Makefile 学习

    Makefile 一、Makefile 简单使用 Makefile是Linux系统下的一种编译脚本,更快、更方便的...

  • Makefile

    在使用Makefile 编译多个c文件时,出现 Makefile:2:*** missing separator....

  • 2-Linux C语言指针与内存-学习笔记

    Linux C语言指针与内存 前面我们对于: c语言的基本用法 makeFile文件的使用 main函数的详解 标...

  • Makefile简笔记

    一、Makefile 变量 #Makefile变量的使用 objects = main.o input.o cal...

  • makefile 基本规则

    Makefile1 前面指定目标, 最前面的目标就是终极目标2 只要实现终极目标即可3 makefile 会先将所...

网友评论

    本文标题:Makefile的基本使用

    本文链接:https://www.haomeiwen.com/subject/gfmkbftx.html