简体   繁体   中英

why do keep getting warnings in this makefile?

CC := cc
NAME := minishell
SRCS = ./Srcs/xsh.c
DIR = .build  
OBJS := $(SRCS:%.c=$(DIR)%.o)
OBJS := $(addprefix $(DIR), $(OBJS))
$(DIR)/%.o : %.c 
    $(CC) -c -o $@ $<
$(NAME) : $(OBJS) | $(DIR)
    $(CC) -o $@ $^
$(DIR):
    mkdir -p $(@)
all : $(NAME)

I am trying to store all.o files in the build directory

Makefile:12: warning: overriding commands for target.build

Makefile:8: warning: ignoring old commands for target.build

make: *** No rule to make target %.c, needed by.build. Stop

Your line numbers are off by one which makes these errors hard to understand. Please be sure to include the exact makefile and errors so that they match up.

However, I assume that line #8 is:

$(DIR)/%.o : %.c 

and line #12 is:

$(DIR):

The only way that this could give that error is if your DIR variable ended in spaces:

DIR = .build  
            ^-space here

Makefiles preserve ending spaces on variables so be sure you don't do that.

Note if you had a newer version of GNU make it would warn about this:

Makefile:8: *** mixed implicit and normal rules: deprecated syntax

I guess that's still not super-helpful but it's something: :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM