Makefile重新链接错误 [英] Makefile relink error
问题描述
我正在尝试使此Makefile重新链接,而不是重新编译未经修改的文件. "libft"是我的库,没有任何错误.我在执行
I am trying to get this makefile relink and not recompile unessecarily files that aren't modified. The "libft" is my library and doesnt have any errors. The error that I am having when doing
make
是:
make: *** No rule to make target `main.o', needed by `ft_printf'. Stop.
我的makefile是:
My makefile is:
NAME = ft_printf
SRC = main.c\
ft_printf.c\
parser_main.c\
utils.c\
debug_funcs.c
OBJ = $(SRC:.c=.o)
SRC_PATH = srcs/
SRC_POS = $(addprefix $(SRC_PATH),$(SRC))
INC = -I includes
LIBFT = libft/libft.a
CC = gcc
FLAGS = -Wall -Wextra -Werror
all: $(NAME)
$(NAME): $(OBJ)
$(CC) $(FLAGS) $(OBJ) -o $(NAME) $(LIBFT)
%.o: %.c
$(CC) -o $@ -c $< $(FLAGS)
$(LIBFT):
make -C ./libft/
clean:
rm -f $(OBJ)
make clean -C ./libft/
fclean: clean
rm -f $(NAME)
make fclean -C ./libft/
re: fclean all
有什么主意吗?我想不通,我认为这是因为未调用%.o:%.c
Any idea ? I can't figure it out and i think it's because %.o:%.c isn't called
推荐答案
鉴于这些变量的存在:
SRC_PATH = srcs/
SRC_POS = $(addprefix $(SRC_PATH),$(SRC))
我猜测您的源文件实际上位于srcs/
中,而您正在.
中构建目标文件,因此,此模式规则:
I'm guessing that your source files actually live in srcs/
whereas you're building your object files in .
So this pattern rule:
%.o: %.c
尝试匹配main.o
时
找不到main.c
,因为该文件确实是srcs/main.c
.由于该模式不匹配,因此不考虑该规则本身,并且由于未找到其他规则,因此会出现错误.
when trying to match main.o
won't find a main.c
since that file really is srcs/main.c
. Since that pattern doesn't match, the rule itself isn't considered, and since no other rule is found, you get an error.
相反,请尝试:
%.o : $(SRC_PATH)/%.c
$(CC) -o $@ -c $< $(FLAGS)
这篇关于Makefile重新链接错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!