Makefile非递归方法问题
我正试图按照我在中收到的指导,使用非递归方法在代码结构下使用Makefile进行构建 下面是MakefileMakefile非递归方法问题,makefile,gnu-make,Makefile,Gnu Make,我正试图按照我在中收到的指导,使用非递归方法在代码结构下使用Makefile进行构建 下面是Makefile -include ../code/subdir.mk all : target_file target_file : ../code/main.o ../code/test.o @echo Building ... @echo Linking files ... gcc -Llib ../code/main.o ../code/test.o -lm -o t
-include ../code/subdir.mk
all : target_file
target_file : ../code/main.o ../code/test.o
@echo Building ...
@echo Linking files ...
gcc -Llib ../code/main.o ../code/test.o -lm -o target_file
clean:
rm -rv ../code/*.o
下面是subdir.mk文件
../code/test.o : ../code/test.c ../code/test.h
@echo Building test.c ...
gcc -Werror -Wall -c ../code/test.c -o ../code/test.o
../code/main.o : ../code/main.c ../code/main.h ../code/test.h
@echo Building main.c ...
gcc -Werror -Wall -c ../code/main.c -o ../code/main.o
我在运行make命令时得到的输出如下
Building test.c ...
gcc -Werror -Wall -c ../code/test.c -o ../code/test.o
我没有得到任何错误,也没有得到main.o。在Makefile中,链接命令也不会执行。这可能是因为默认情况下,
make
生成它遇到的第一个目标。由于在all:target\u文件
行之前包含subdir.mk
,因此将生成subdir.mk
中命名的第一个目标,而不生成其他目标。解决方案:将子目录mk
放在最后,例如靠近末端
Building test.c ...
gcc -Werror -Wall -c ../code/test.c -o ../code/test.o