20、makefile 之echo \ $^ exec

本文主要介绍makefile中的特殊符号$^的含义,它代表所有依赖的文件。同时讲解了如何使用@echo进行命令行打印,以及如何利用换行符在makefile中编写多行命令。通过示例展示了在执行`make exec`时,如何执行特定的操作,如打印路径。

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

首先基于上篇文章makefile 的初认识,我们继续学习makefile 新东西(hello.cpp test.h文件和上文类同不在细谈)着重学习makefile;

mkdir -p test
cd test
mkdir function
touch hello.cpp
vi hello.cpp
mkdir source
touch test.h
vi test.h
cd ..
touch makefile
vi makefile

同样建立操做和三个文件

#include<iostream>
using namespace std;
void print()
{cout<<"i am a student"<<endl;}

test.h文件

#include"../function/test.h"
#include<iostream>
using namespace std;
int main(int argc,char* argv[])
{cout<<"hello world"<<endl;
print();
return 0;
}

hello.cpp文件

VPATH=./source
CC=g++
#vpath %.cpp source
#vpath %.h  function
object=hello.o 
hello:$(object)
	@ echo 正在编译文件 $<
	$(CC)  -o $@ -g $^
$(object):hello.cpp 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

sxj731533730

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值