clang'链接器'输入未使用

问题描述 投票:0回答:1

首先,我的文件树是这样的。

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

我的makefile就是这样。

.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

发生错误。

[clang:错误:-lft:'链接器'输入未使用[-Werror,-Wunused-command-line-argument]

[clang:错误:-lmlx:'链接器'输入未使用[-Werror,-Wunused-command-line-argument]

clang:错误:-lm:'链接器'输入未使用[-Werror,-Wunused-command-line-argument]

[clang:错误:-framework OpenGl:'链接器'输入未使用[-Werror,-Wunused-command-line-argument]

[clang:错误:-framework AppKit:'链接器'输入未使用[-Werror,-Wunused-command-line-argument]

clang似乎说我的标志没有使用。我做错了什么?

c macos makefile clang
1个回答
2
投票

您有:

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

编译为目标文件时无需指定库。因此,您需要:

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

我并不完全相信该配方(我认为只要其中任何一个更改,所有源文件都会被重新编译),但是删除库可以避免将链接时参数(库)传递给不会被编译的编译器。之所以使用,是因为未发生链接。

© www.soinside.com 2019 - 2024. All rights reserved.