makefile学习小记(一)

本文通过一个简单的C语言程序实例介绍了Makefile的基本语法和构建过程。包括如何定义目标文件、依赖文件及编译命令等关键概念。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Makefile一直没有仔细的去看看,最近下狠心看了看,有一些收获;

先来看看这个例子:


main.c:

#include "dep.h"
void main()
{
        dep(1);
        printf("we are in main now !\n");
}


dep.c:

#include "dep.h"
void dep(int i)
{
        printf("copy from main is %d\n",i);
}


dep.h:

#include <stdio.h>
void dep(int i);

再来看看Makefile:

test : main.o dep.o
        cc -o test main.o dep.o
main.o : main.c dep.h
        cc -c main.c
dep.o : dep.c dep.h
        cc -c dep.c

注意:

(1)makefile 结构是:

          target file : dependency file

          【tab】    command

          也就是说,command之前必须得有Tab键;

(2)Make 之后的流程:

         1.make之后会寻找Makefile

         2.查找第一个目标文件,也就是本例子中的test

         3.如果没有test,检查有没有以来文件main.o和test.o,如果缺其一,则用规则生成依赖文件。




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值