'make' does not recompile when source file has been edited

旧城冷巷雨未停 提交于 2019-12-01 21:49:06

Because you haven't told it that recompilation depends on functions.h.

Try adding this to your Makefile:

%.o : functions.h

Alternatively, modify your existing rule to be:

%.o : %.c functions.h
    $(CC) -c $< -o $@

You've told make that .o files don't depend on .h files, so it doesn't recompile anything when a header changes.

Getting it to work right is hard (you need to generate dependencies for each .c file), but an easy way is just to define HEADERS which contains all your header files and make each .o file depend on all your headers.

Eldar Abusalimov

If you're using GCC (well, you are), then it can be solved generically by passing -MD option to the compiler, GCC will generate a file containing Make dependencies on included headers:

CC = gcc
OBJECTS = main.o functions.o

%.o : %.c
    $(CC) -MD -c $<

-include $(OBJECTS:.o=.d)

Some headers-related information can also be found in this question.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!