我有这个hello-world.c
,我想编译为hello-world
二进制。但是hello-world.c
取决于在../helpers/a.c
和../helpers/b.c
中定义的几个函数,并且这些帮助者中的每一个分别包括../helpers/a.h
和../helpers/b.h
。Makefile对于具有多个.c和.h依赖关系的单个目标
我当前的Makefile看起来像
CC = @gcc
CFLAGS = -g -Wall -Wextra -Werror
CFLAGS +=
LDLIBS =
LDLIBS +=
OBJS = ../helpers/a.o ../helpers/b.o
SOURCES = hello-world.c
DESTS = hello-world
new: clean all
clean:
@rm -rf *.o */*.o $(DESTS)
all: $(OBJS) $(DESTS)
%.o: %.c
$(CC) $(CFLAGS) -c $< -o [email protected]
%: %.c
$(CC) $(CFLAGS) -o [email protected] $<
,但它不工作,返回make: *** No rule to make target `../helpers/a.o', needed by `all'. Stop.
我明白,Makefile中似乎没有看到%.o
规则,但我没有看到为什么。
编辑:Makefile的调试:
[email protected]:/media/sf_procmon/procmon$ make --debug=b
GNU Make 3.81
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
This program built for x86_64-pc-linux-gnu
Reading makefiles...
Updating goal targets....
File `new' does not exist.
File `clean' does not exist.
Must remake target `clean'.
Successfully remade target file `clean'.
File `all' does not exist.
File `../helpers/a.o' does not exist.
Must remake target `../helpers/a.o'.
make: *** No rule to make target `../helpers/a.o', needed by `all'. Stop.
对其他文件夹中的文件使用模式规则适用于我。我运行这个makefile,a.o和b.o是按照预期创建的。你确定你在正确的目录下运行'make all'吗? –
嗯,这很奇怪。我在右侧运行make,但是我得到了这个错误。 – alexandernst
为什么不把你的帮助函数放到一个库中?那么你不必每次都编译它们。 –