У меня есть 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
, но я не вижу Зачем.
Edit: 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.
Использование шаблонов правил для файлов в других папках работает для меня. Я запустил этот make-файл, и a.o и b.o были созданы, как ожидалось. Вы уверены, что используете 'make all' в правильном каталоге? –
Хм, это странно. Я запускаю make inhe right dir, но я получаю эту ошибку. – alexandernst
Почему бы не помещать ваши вспомогательные функции в библиотеку? Тогда вам не придется собирать их каждый раз. –