Hack Forums
[Shell] [Makefile] No rule to make target... - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [Shell] [Makefile] No rule to make target... (/showthread.php?tid=5767566)



[Makefile] No rule to make target... - misterfail88 - Dec 13, 2017

Hi,

I have a problem with Makefile. He which should compile .c file to an object file only if a .c file has been modified.
But i have an error when i use "all" rule :
Code
make: *** No rule to make target `obj/main.o', needed by `ft_ls'.  Stop.

When i use manually it's works :

Code
clang -Wall -Wextra -Werror -Iinclude -o obj/main.o -c src/main.c
 
My work directory :
Code
Makefile include/*.h  libft/libft.a    src/*.c

Makefile content :
Code
NAME = ft_ls
SRC_PATH = src
OBJ_PATH = obj
CPPFLAGS = -Iinclude
LDFLAGS = -Llibft
LDLIBS = -lft
CFLAGS = -Werror -Wall -Wextra
CC = clang
SRC_NAME = main.c\
     ft_type.c\
     ft_right.c\
     ft_putright.c\
     ft_date_converter.c
OBJ_NAME = $(SRC_NAME:.c=.o)
SRC = $(addprefix $(SRC_PATH)/,$(SRC_NAME))
OBJ = $(addprefix $(OBJ_PATH)/,$(OBJ_NAME))

all: $(NAME)

$(NAME): $(OBJ)
   $(CC) $(LDFLAGS) $(LDLIBS) $^ -o $@
   make -C libft

$(OBJ_PATH)%.o: $(SRC_PATH)%.c
   @mkdir $(OBJ_PATH) 2> /dev/null || true
   $(CC) $(CFLAGS) $(CPPFLAGS) -o $@ -c $<

clean:
   rm -fv $(OBJ)
   make -C libft clean
   @rmdir $(OBJ_PATH) 2> /dev/null || true

fclean: clean
   rm -fv $(NAME)
   make -C libft fclean

re: fclean all

.PHONY: all, clean, fclean, re

If you have some idea i'll take it  😁
Thx

'/' missing
$(OBJ_PATH)%.o: $(SRC_PATH)%.c ==> $(OBJ_PATH)/%.o: $(SRC_PATH)/%.c


RE: [Makefile] No rule to make target... - HFDone - Dec 13, 2017

add directory for obj/main.o


RE: [Makefile] No rule to make target... - misterfail88 - Dec 13, 2017

(Dec 13, 2017 08:43 AM)HFDone Wrote:  add directory for obj/main.o

Directory will be create automatically.

But my problem is solved :

'/' missing

$(OBJ_PATH)%.o: $(SRC_PATH)%.c ==> $(OBJ_PATH)/%.o: $(SRC_PATH)/%.c