makefile简介

一、 makefile格式
    1. makefile的文件名可以是makefile也可以是Makefile。
    2. 定义变量
        <变量名> = <内容>
    3. 使用变量
        $(<变量名>)
        例如:
        CC = gcc
            $(CC) main.c
    4. 标准makefile格式。
        target : prerequisites
            <tab>command
    5. 隐藏本身命令输出
        command前面添加'@'。
    6. 注销使用'#'。

二、 make的执行规则
    1. make会自上到下读取makefile文件。
    2. make只有一个主target。也就是说,只有与makefile中第一个target有关的target才会被执行。
        若想生成多个可执行文件,可定义一个命令为空的主target,这个target的条件可以是多个可执行文件。
    3. make<空格><target>可以只执行某一target,以及它依赖的prerequisites。

三、 例子
    1. Makefile

    xxxx : main
        #make clean

    main : main.cpp tool.o
        g++ main.cpp tool.o -o main
    tool.o : tool.cpp tool.h
        @g++ -c tool.h tool.cpp

    clean :
        rm -rf *.o *.gch

    2. 执行结果

$ make
g++ main.cpp tool.o -o main
#make clean

 

参考:https://www.bilibili.com/video/av10298403?from=search&seid=1511585135233301511

posted @ 2020-03-08 00:28  看不见的R  阅读(420)  评论(0)    收藏  举报