Makefile dealing with header files

戏子无情 提交于 2019-12-13 22:54:19

问题


The following is my makefile:

CC=gcc
CFLAGS=-Wall -O3
SRCS = $(wildcard *.c)
EXES = $(patsubst %.c,%,$(SRCS))
.c.o:
        $(CC) $(CFLAGS) -c $<
SRC_CODE=\
        file1.c\
        file2.c\
        file.h
SOFI2D_OBJ=$(SRC_CODE:%.c=%.o)
sofi2D: $(SOFI2D_OBJ)
        $(CC) $^ -o $@
clean:
        rm -rf *.o *.o* *~ $(EXES)   
all: clean sofi2D

I wonder how the header file (.h) plays a role in the compilation? Because all the operations are on .c files...


回答1:


The header file is used by the C compiler, not make.

If you want the .c files to be rebuilt if file.h changes, then you need to change the definition of SRC_CODE:

SRC_CODE = file1.c file2.c
$(SRC_CODE): file.h


来源:https://stackoverflow.com/questions/49393912/makefile-dealing-with-header-files

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