AMATEUR_TOSS
AMATEUR_TOSS

Reputation: 275

clang 'linker' input unused

First, my file tree is like this.

cub3d
|---- includes
|     |---- cub3d.h
|---- libft
|     |---- Makefile
|     |---- libft.a
|     |---- includes
|     |     |---- libft.h
|     |---- obj
|     |     |---- objectfile for libft library
|     |---- srcs
|     |     |---- sourcefile for libft library
|---- minilibx
|     |---- all of file for minilibx libarary(.a, .h, .c ...etc...)
|---- obj
|     |---- main.o
|---- srcs
|     |---- main.c
|---- Makefile

And my makefile is like this.

.PHONY: all clean fclean re

NAME = test

CC = gcc
CFLAGS = -Wall -Wextra -Werror -I $(INC_DIR)\ 
         I$(LIBFT_INC) -I $(MLX_INC)

SRC_DIR = ./srcs/
SRCS = $(addprefix $(SRC_DIR), $(SRC))
SRC =   main.c

OBJ_DIR = ./obj/
OBJS = $(addprefix $(OBJ_DIR), $(OBJ))
OBJ = $(SRC:.c=.o)

INC_DIR = includes

LIBFT_DIR = libft
LIBFT_INC = libft/includes
LIBFT_LIB = -L $(LIBFT_DIR) -lft

MLX_DIR = minilibx
MLX_INC = $(MLX_DIR)
MLX_LIB = -L $(MLX_DIR) -lmlx -lm -framework OpenGL\
           -framework AppKit

all: libft_make minilibx_make $(NAME)

$(NAME): $(OBJ_DIR) $(OBJS)
    @$(CC) $(CFLAGS) -o $@ $(OBJS) $(LIBFT_LIB) $(MLX_LIB)
$(OBJS): $(SRCS)
    @$(CC) $(CFLAGS) -o $@ -c $(SRCS) $(LIBFT_LIB) $(MLX_LIB)

$(OBJ_DIR):
    @mkdir -p $(OBJ_DIR)

libft_make:
    @make -C libft

minilibx_make:
    @make -C minilibx

clean:
    @rm -f $(OBJS)
    @rm -rf $(OBJ_DIR)
    @make -C libft/ clean
    @echo "$(_RED)'"libft/$(OBJ_DIR)"' has been deleted. $(_END)"
    @echo "$(_RED)'"$(OBJ_DIR)"' has been deleted. $(_END)"

fclean: clean 
    @rm -f $(NAME)
    @make -C libft/ fclean
    @echo "$(_RED)'"libft.a"' has been deleted. $(_END)"
    @echo "$(_RED)'"$(NAME)"' has been deleted. $(_END)"

rma: clean fclean

re: fclean all

make -n

make -C libft
make -C minilibx
gcc -Wall -Wextra -Werror -I includes -I libft/includes -I minilibx -o obj/main.o -c srcs/main.c -L ./libft -lft -L minilibx -mlx -lm -framework OpenGL -framework Appkit
gcc -Wall -Wextra -Werror -I includes -I libft/includes -I minilibx -o test ./obj/main.o -L libft -lft -L minilibx -lmlx -lm -framework OpenGL -framework Appkit

An error has occurred.

clang: error: -lft: 'linker' input unused [-Werror, -Wunused-command-line-argument]

clang: error: -lmlx: 'linker' input unused [-Werror, -Wunused-command-line-argument]

clang: error: -lm: 'linker' input unused [-Werror, -Wunused-command-line-argument]

clang: error: -framework OpenGl: 'linker' input unused [-Werror, -Wunused-command-line-argument]

clang: error: -framework AppKit: 'linker' input unused [-Werror, -Wunused-command-line-argument]

clang seems to say that my flags are not used. What did I do wrong?

Upvotes: 1

Views: 5224

Answers (1)

Jonathan Leffler
Jonathan Leffler

Reputation: 753455

You have:

$(OBJS): $(SRCS)
    @$(CC) $(CFLAGS) -o $@ -c $(SRCS) $(LIBFT_LIB) $(MLX_LIB)

You don't need to specify the libraries when compiling to object files. Therefore, you need:

$(OBJS): $(SRCS)
    @$(CC) $(CFLAGS) -o $@ -c $(SRCS)

I'm not entirely convinced by the recipe (I think that all the source files will be recompiled whenever any of them changes), but dropping the libraries avoids passing link-time arguments (libraries) to the compiler that won't be used because linking is not occurring.

Upvotes: 2

Related Questions