当我将所有文件都包含在同一文件夹中并运行以下命令时,我为C项目编写了一个makefile:
make
all is fine. But when I move map.c
& map.h
inside mtm_map folder (which exists inside the current folder) I got an error:
-bash-4.2$ ls
election.c extended_map.c main.c makefile test_utilities.h utilities.h
election.h extended_map.h main.o mtm_map utilities.c
-bash-4.2$ ls mtm_map
map.c map.h
-bash-4.2$ make
gcc -c -DNDEBUG -std=c99 -Wall -pedantic-errors -Werror mtm_map/map.c
mtm_map/map.c:2:23: fatal error: utilities.h: No such file or directory
#include "utilities.h"
^
compilation terminated.
make: *** [mtm_map/map.o] Error 1
-bash-4.2$
我的makefile:
CC = gcc
OBJS = main.o mtm_map/map.o extended_map.o election.o utilities.o
EXEC = election
DEBUG_FLAG = -DNDEBUG
COMP_FLAG = -std=c99 -Wall -pedantic-errors -Werror
$(EXEC) : $(OBJS)
$(CC) $(DEBUG_FLAG) $(OBJS) -o $@
main.o: main.c mtm_map/map.h election.h test_utilities.h
$(CC) -c $(DEBUG_FLAG) $(COMP_FLAG) $*.c
mtm_map/map.o: mtm_map/map.c mtm_map/map.h utilities.h
$(CC) -c $(DEBUG_FLAG) $(COMP_FLAG) $*.c
extended_map.o: extended_map.c extended_map.h mtm_map/map.h utilities.h
$(CC) -c $(DEBUG_FLAG) $(COMP_FLAG) $*.c
election.o: election.c election.h mtm_map/map.h extended_map.h utilities.h
$(CC) -c $(DEBUG_FLAG) $(COMP_FLAG) $*.c
utilities.o: utilities.c utilities.h
$(CC) -c $(DEBUG_FLAG) $(COMP_FLAG) $*.c
clean:
rm -f $(OBJS) $(EXEC)
编辑:我得到的乳胶错误:
gcc -c -DNDEBUG -std=c99 -Wall -pedantic-errors -Werror main.c
gcc -c -DNDEBUG -std=c99 -Wall -pedantic-errors -Werror mtm_map/map.c
gcc -c -DNDEBUG -std=c99 -Wall -pedantic-errors -Werror extended_map.c
gcc -c -DNDEBUG -std=c99 -Wall -pedantic-errors -Werror election.c
gcc -c -DNDEBUG -std=c99 -Wall -pedantic-errors -Werror utilities.c
gcc -DNDEBUG main.o mtm_map/map.o extended_map.o election.o utilities.o -o election
gcc: error: mtm_map/map.o: No such file or directory
make: *** [election] Error 1
-bash-4.2$