栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

Linux系统编程 35 -makefile基础规则

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Linux系统编程 35 -makefile基础规则

Linux系统编程 35 -makefile基础规则

学习笔记

脚本:把一些列命令集合放在一个文件中,批量执行。


makefile的知识点初期入门
1个规则
2个函数
3个自动变量


规则

若想生成目标,检查规则中依赖是否存在,如不存在,
则寻找是否有规则用来生成该依赖文件


目标: 依赖条件
    (一个tab缩进)命令
    
    
一个tab缩进,不能多也不能少
1.目标
2.依赖条件
3.命令
这三部分称之为一个规则

$cd 35maketest/
$ls
hello.c
$cat hello.c
#include
#include
#include
#include
#include

int main(int argc, char *argv[])
{

    return 0;
}

makefile的命名有两种
1.$touch makefile
2.$touch Makefile

$cat makefile
hello:hello.c
    gcc hello.c -o hello

输入make

$make
gcc hello.c -o hello
$ls
hello  hello.c  makefile


,如不存在,
则寻找是否有规则用来生成该依赖文件
这句话的理解


gcc 编译有四步
gcc -c hello.c -o hello.o
gcc hello.o -o hello

$cat makefile 
hello:hello.o
    gcc hello.o -o hello.out
hello.o:hello.c
    gcc -c  hello.c -o hello.o

make 是一个命令工具,它解释 Makefile 中的指令(应该说是规则)。
在 Makefile文件中描述了整个工程所有文件的编译顺序、编译规则。

$make
gcc -c  hello.c -o hello.o
gcc hello.o -o hello.out
$./hello.out 
$


 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/657006.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号