【发布时间】:2019-02-04 17:36:59
【问题描述】:
我正在尝试使用Makefile 来管理我的项目周围的一些任务(例如打包它以进行分发)。但是我找不到依赖特定文件名而不是一些自动魔术的方法。见例子:
+ $ cat Makefile
dist: ctl
echo "package it here"
+ $ tree
.
├── ctl
└── Makefile
0 directories, 2 files
+ $ make
echo "package it here"
package it here
如您所见,这很好用。但是当我创建文件 ctl.h 和 ctl.c 时它停止工作:
+ $ touch ctl.{h,c}
+ $ make
cc ctl.c -o ctl
/usr/bin/ld: /usr/lib/gcc/x86_64-pc-linux-gnu/8.2.1/../../../../lib/Scrt1.o: in function `_start':
(.text+0x24): undefined reference to `main'
collect2: error: ld returned 1 exit status
make: *** [<builtin>: ctl] Error 1
+ $ tree
.
├── ctl.c
├── ctl.h
└── Makefile
0 directories, 3 files
我的假设是make 试图变得聪明,并认为ctl 是从ctl.c 编译的程序。这不是这样的情况。如何抑制这种行为?
【问题讨论】:
-
为构建
ctl定义一个显式规则,这样它就不会使用内置规则。 -
dist依赖于ctl的原因是什么?如果您只想在文件ctl被修改的情况下运行dist的命令,则目标dist必须创建一个文件dist。如果dist是一个虚假目标,那么除了应该在dist之前执行的其他虚假目标之外,拥有依赖项是没有意义的,例如dist: all如果你想在运行dist命令之前自动make all。 -
只是为了保证
ctl在dist开始运行之前存在 -
这和
automake标签有什么关系?
标签: c++ c makefile gnu-make automake