我写了简单的代码* make_test *来测试makefile的功能。文件夹结构如下:makefile的自动操作
包括文件夹包含maths.h
float add(float a, float b) { return a+b; }
主文件包含以下代码:
# include <stdio.h> # include <include/maths.h> int main(int argc, char** argv) { float a=1; float b=4; printf("%f + %f = %f\n", a, b, add(a, b)); return 0; }
生成文件其中包含以下内容:
IDIR = -I. DEPS = ./include/maths.h CC= gcc -Wall -g $(IDIR) program: make_test.o %.o: test/%.c $(DEPS) @echo "Rule 1 was called" $(CC) -o [email protected] $< %.o: test/%.c $(DEPS) @echo "Rule 2 was called" $(CC) -o [email protected] $< %.o: test/%.c $(DEPS) @echo "Rule 3 was called" $(CC) -o [email protected] $<
注意,有测试/%。被刻意插入测试C语句。 没有测试文件夹。如果我让在主文件的变化,我输入make命令行中,我得到
gcc -Wall -g -I. -c -o make_test.o make_test.c
我的问题是,我还没有添加-c标志的任何地方那么为什么它出现在输出?不应该存在“Nothing to do”输出,因为不存在依赖关系(test /%。c)或更改(include/maths.h)?
感谢,