2

Hello I can't make my Makefile working with
$(CC) $(CFLAGS) $(INC) $(OBJS) $(MLX_LNK) -o $(NAME).
got a

clang -O3 -Wall -Wextra -Werror -I -I cub3d.h src/cub3d.o src/checks/argvcheck.o src/checks/parse_map.o src/libft/basics.o src/libft/basics_bis.o src/libft/get_next_line.o src/utils/errors.o -L minilibx_opengl -lmlx -framework OpenGL -framework AppKit -o cub3D clang: error: cannot specify -o when generating multiple output files make: *** [cub3D] Error 1 

The command on terminal I do is "make test1"

I also tried with $(CC) $(CFLAGS) -I $(HEADER) $(OBJS) $(MLX_LNK) -o $(NAME).

but got

Compiling... clang -O3 -Wall -Wextra -Werror -I cub3d.h src/cub3d.o src/checks/argvcheck.o src/checks/parse_map.o src/libft/basics.o src/libft/basics_bis.o src/libft/get_next_line.o src/utils/errors.o -L minilibx_opengl -lmlx -framework OpenGL -framework AppKit -o cub3D Undefined symbols for architecture x86_64: "_init_cube", referenced from: _init_game in cub3d.o "_write_errors", referenced from: _verify_line in argvcheck.o _ft_parse_cub in argvcheck.o _my_get_next_line in get_next_line.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) 

Many thanks for your help

Makefile here :

NAME = cub3D HEADER = cub3d.h CC = clang CFLAGS = -O3 -Wall -Wextra -Werror INC = -I $(MLX-DIR) -I $(HEADER) MLX_DIR = minilibx_opengl MLX_LNK = -L $(MLX_DIR) -lmlx -framework OpenGL -framework AppKit SRCS = src/main.c \ src/checks/argvcheck.c \ src/libft/basics.c \ src/libft/get_next_line.c \ src/utils/errors.c \ OBJS = $(SRCS.c=.o) all: $(NAME) mlx: $(MLX-DIR) @echo "\033[34m-= Making libX.a... =-" @make -C $(MLX_DIR) $(NAME): ${OBJS} mlx $(CC) $(CFLAGS) $(INC) $(OBJS) $(MLX_LNK) -o $(NAME) test1: $(NAME) $(NAME) ; ./a.out maps/test1.cub clean: @echo "\033[0;31mCleaning..." rm -f $(OBJS) # + $(B_OBJ) # + rm -f bitmap.bmp @echo "\033[0m" fclean: clean @echo "\033[34m-= Cleaning mlx... =-" @make clean -C $(MLX_DIR) @echo "\033[0;31mRemoving executable..." rm -f $(NAME) @echo "\033[0m" re: fclean all .PHONY: all clean fclean re ```` 

1 Answer 1

1

Well, first of all this is wrong:

OBJS = $(SRCS.c=.o) 

You're missing a : here, it should be $(SRCS:.c=.o) As a result, OBJS will be empty.

Next, this is not causing you problems at the moment but is not right: you should always use $(MAKE) never a raw command like make when invoking a sub-make.

Finally, the way you've written your question by embedding results into the middle of the makefile makes it very hard to read. Please put the makefile first, then separate sections for different attempts at recipes. And you need to include the command line that make printed out (cut and paste the exact line please!) for us to see what the command being run it (with all variables expanded). Typically it becomes VERY obvious what the problem is if you look at that.

For example in this case you'd see that there are actually no object files in the link line, so it should be clear that the $(OBJS) variable is not being set properly.

EDIT

OK, thanks for showing the command line. Now, you should look at it carefully and you will see your problem :). Look at this here:

clang -O3 -Wall -Wextra -Werror -I -I cub3d.h src/cub3d.o ... 

Does that look right to you? Look specifically at -I -I cub3d.h... does that seem right?

What happens is that the compiler expects a pathname to come after the -I and there isn't one, so it treats the second -I as the pathname. Then the file cub3d.h is treated as a source file, and you can't link a source file with object files.

So why does this look like this? Look at your makefile:

INC = -I $(MLX-DIR) -I $(HEADER) 

so the missing thing is where $(MLX-DIR) goes. What is that variable? Well you have this:

MLX_DIR = minilibx_opengl 

but this is not the same thing because it uses an underscore whereas the reference uses a dash. So, make them the same.

Then you'll see that it's not valid to put a file as an argument to -I. That takes a directory to search for header files. If you want to include the header you have to add #include "cub3d.h" in your source code, not add it to the compile line.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for the missing ":", now I know why the executive was disappearing. Sorry for the confusion, here is a cleaner Makefile.
I should also say, it's useless to add -I options to the link line. The linker doesn't search for headers, the compiler searches for headers. -I options should be added to the compile line. You can add that to CFLAGS if you want, or you can set the CPPFLAGS variable instead of using INC (CPPFLAGS is the default variable holding preprocessor options like -I or -D).
Thank you very much for this lesson, it works finally well now !

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.