我有这个makefile(我剪掉了不相关的部分):
CC = gcc
EXEC = mtm_cm
LIB = -L. -lmtm
DEBUG = -g
CFLAGS = -std=c99 -Wall -Werror -pedantic-errors -DNDEBUG $(DEBUG)
OBJS = command_parser.o course_manager.o grade_data.o student.o \
grade_sheet_data.o print_utilities.o semester.o string_utilities.o
$(EXEC): $(OBJS) main.o
$(CC) $(DEBUG) $(OBJS) main.o $(LIB) -o $@
... here the $(OBJS) targets are found ...
tests: $(OBJS) student_test grade_data_test
grade_data_test: tests/grade_data_test.o
$(CC) $(DEBUG) $(OBJS) tests/$@.o $(LIB) -o $@
student_test: tests/student_test.o
$(CC) $(DEBUG) $(OBJS) tests/$@.o $(LIB) -o $@
tests/student_test.o: tests/student_test.c tests/new_test_utilities.h \
student.h list.h grade_sheet_data.h
tests/grade_data_test.o: tests/grade_data_test.c tests/new_test_utilities.h \
grade_data.h grade_sheet_data.h list.h
除了grade_data部分外,一切正常
也就是说,如果我致电make
,则会创建可执行文件mtm_cm
,如果我致电make tests
,则会创建student_test
,但不会grade_data_test
。<登记/>
相反,我收到一个错误:
... former successful compilations ...
gcc -g command_parser.o course_manager.o grade_data.o student.o grade_sheet_data.o print_utilities.o semester.o string_utilities.o tests/grade_data_test.o -L. -lmtm -o grade_data_test
gcc: tests/grade_data_test.o: No such file or directory
但它不仅仅是跳过了目标grade_data_test
的依赖关系。相反,让我们运行make tests/grade_data_test.o --debug=v
,并获得输出:
...
Finished prerequisites of target file `tests/grade_data_test.o'.
Must remake target `tests/grade_data_test.o'.
Successfully remade target file `tests/grade_data_test.o'.
make: `tests/grade_data_test.o' is up to date.
但该文件不存在。 目录有足够的权限,我没有与文件同名的目录。
你能帮我找出解决方案吗?