Answer the question
In order to leave comments, you need to log in
How to save object files in gcc (in a different folder)?
I don’t know how the object files are in a separate folder ... I searched the Internet, found only ways to call Satan from the compiler, but there are no files ... if anything, then the Makefile is like this:
NAME = calc
SRC = main.c \
parser.c \
ft_lib/ft_atoi.c \
ft_lib/ft_putchar.c \
ft_lib/ft_putnbr.c
OBJ = *.o
FLAGS = #-Wall -Wextra -Werror
all: $(NAME)
$(NAME):
gcc $(SRC) $(FLAGS) -c
gcc $(OBJ) -o $(NAME)
clean:
rm -f $(OBJ)
fclean:
rm -f $(NAME)
re: fclean all
Answer the question
In order to leave comments, you need to log in
How to save object files in gcc
-o
-- path to result, preprocessing/compiling/linking. Teach your Makefile to substitute the correct path for this option. NAME = calc
SRC = main.c \
parser.c \
ft_lib/ft_atoi.c \
ft_lib/ft_putchar.c \
ft_lib/ft_putnbr.c
BUILDDIR=build
OBJ = $(addprefix $(BUILDDIR)/,$(subst /,_,$(patsubst %.c,%.o,$(SRC))))
FLAGS = #-Wall -Wextra -Werror
all: $(NAME)
$(NAME): $(OBJ)
gcc $(OBJ) -o $(NAME)
define CC_RULE =
$(BUILDDIR)/$(subst /,_,$(patsubst %c,%o,$(SOURCE))): $(SOURCE)
gcc $(FLAGS) -c $< -o [email protected]
endef
$(foreach SOURCE,$(SRC),$(eval $(call CC_RULE,$(SOURCE))))
clean:
rm -f $(OBJ)
fclean:
rm -f $(NAME)
re: fclean all
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question