linux下的项目组成

linux下的项目组成


1认识Makefile

程序的自动编译
当程序中有多个源文件时,
先编译:
g++ ‐c main.cpp ‐o main.o
g++ ‐c other.cpp ‐o other.o
再链接
g++ main.o other.o ‐o helloworld
考虑:能不能写一个脚本,自动执行所有的步骤
对比:在VC下面,我们点一个“生成解决方案”就能 生成整个项目了。。。。

Makefile
Makefile是一个描述“如何生成整个项目”的脚 本文件
方法:
① 创建一个文件叫Makefile
② 输入命令,根据Makefile里面的指示,自动执 行所有的步骤
make ‐f Makefile
(或者直接make 不带参数)

演示1: helloworld: g++ main.cpp other.cpp ‐o helloworld

Makefile的写法
Makefile就是一个普通的文本文件。。。
它由很多条“规则rule”组成,这些规则就是描 述了“先干什么、后干什么”。。。
每一条规则的格式为:
target: dependencies
【TAB】system command1
【TAB】system command2
【TAB】system command…

target: dependencies
【TAB】 system command1
【TAB】 system command2
【TAB】 system command…

target: 目标 ,
dependencies: 依赖
【TAB】: 每行命令前必须插一个TAB
system command: 系统命令

读作:要完成目标target,必须执行命令commands…

演示1
helloworld:
【TAB】g++ main.cpp other.cpp ‐o helloworld

演示2
helloworld:
【TAB】g++ ‐c main.cpp ‐o main.o
【TAB】g++ ‐c other.cpp ‐o other.o
【TAB】g++ main.o other.o ‐o helloworld

Makefile的写法
当存在很多规则时,默认从第一条规则开始 执行。 也可以显式地执行某条规则。

演示2
helloworld:
【TAB】g++ ‐c main.cpp ‐o main.o
【TAB】g++ ‐c other.cpp ‐o other.o
【TAB】g++ main.o other.o ‐o helloworld
clean:
【TAB】rm ‐rf *.o helloworld

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值