make makefile 的使用

43 篇文章 0 订阅
30 篇文章 0 订阅

首先创建几个文件:

main.c:

#include "mytool1.h"
#include "mytool2.h"
int main(int argc , char **argv)
{
	mytool1_print("hello/n");
	mytool2_print("hello/n");
	return 0;
}

mytool1.c:

#include "mytool1.h"
void mytool1_print(char *print_str)
{
	printf("This is mytool1 print %s\n",print_str);
}
mytool1.h:

#include<stdio.h>
#ifndef _MYTOOL_1_H
#define _MYTOOL_1_H
void mytool1_print(char *print_str);
#endif
mytool2.c:

#include "mytool2.h"
void mytool2_print(char *print_str)
{
	printf("This is mytool2 print %s\n",print_str);
}

mytool2.h:

#include<stdio.h>
#ifndef _MYTOOL_2_H
#define _MYTOOL_2_H
void mytool2_print(char *print_str);
#endif
而makefile文件这样写:

#这是上面那个程序的Makefile文件
main:main.o mytool1.o mytool2.o
	gcc -o main main.o mytool1.o mytool2.o
main.o:main.c mytool1.h mytool2.h
	gcc -c main.c
mytool1.o:mytool1.c mytool1.h
	gcc -c mytool1.c
mytool2.o:mytool2.c mytool2.h
	gcc -c mytool2.c

注意的一点是,gcc前边一定要有个tab,否则会出现:makefile:2: *** 遗漏分隔符 。 停止。

运行的时候,直接用终端找到这些文件放的路径下,直接一个命令:make就可以了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
makemakefile是在Linux系统上编译大型项目时常用的工具。通过使用make工具和makefile文件,我们可以将大型的开发项目分解成多个更易于管理的模块,从而简洁明快地处理各个源文件之间复杂的相互关系。make工具可以自动完成编译工作,并且只对程序员在上次编译后修改过的部分进行编译,从而提高项目开发的效率。\[1\] make是一种转化文件形式的工具,它可以将源文件转换生成目标文件,同时检查文件之间的依赖关系。make根据依赖文件的修改时间来判断是否需要重新编译。make使用makefile文件来确定目标文件的依赖关系,并将生成目标文件的相关命令传递给shell执行。\[2\] 在makefile中,可以将最终可执行文件名和"all"同时作为第一条规则的目标。这样,在执行make命令时,会根据可执行文件和依赖关系来判断是否执行命令。也可以使用"make all"来强制执行命令。\[3\] #### 引用[.reference_title] - *1* *3* [makemakefile详解](https://blog.csdn.net/weixin_43966547/article/details/124191491)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [Linux操作系统中的makemakefile介绍](https://blog.csdn.net/liitdar/article/details/123694953)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值