EmanRuoy
EmanRuoy

Reputation: 87

makefile file format not recognized

what i'm doing wrong? And can you send some helpful links to make my work with makefiles easier and better?

get_next_line.o: file not recognized: File format not recognized
collect2: error: ld returned 1 exit status
Makefile:27: recipe for target 'gnl' failed
make: *** [gnl] Error 1

+++

SRC = gnl.c
OBJ = $(SRC:.c=.o)
INCLUDES = gnl.h
NAME = gnl
CFLAGS = -Wall -Werror -Wextra
CC = gcc
DIR = LIBFT

%.o: %.c $(SRC) $(INCLUDES)
        $(CC) $(CFLAGS) -c $<

all: $(NAME)

$(NAME): $(OBJ)
        make -C $(DIR)
        $(CC) $(CFLAGS) -o $(NAME) $(OBJ) -L. $(DIR)/libft.a
clean:
        make clean -C $(DIR)
        rm -f $(OBJ)

fclean:
        make fclean -C $(DIR)
        rm -f $(NAME)

re: fclean all

Upvotes: 3

Views: 26665

Answers (4)

Christophe J. Ortiz
Christophe J. Ortiz

Reputation: 319

It can even be simpler... It just happened to me with a Makefile. In the line (in the Makefile) that creates the executable, where there are different names of objects .o, there was a typo. I left the name of the file .cu (CUDA format) instead of .o.

Upvotes: 1

bballdave025
bballdave025

Reputation: 1428

I ran into this error recently, and I have a couple of suggestions that might help. My problem was not a bad .o file, but rather a 32-bit installation rather than a 64-bit installation. If this is the case for you, too, you might get more complete functionality by trying this solution.

In my case, the makefile(s) in question needed different CFLAGS depending on whether the installation was 64-bit or 32-bit. Here are some lines from the README of the project I was trying to make.

By default, the C/C++ software are compiled in 32 bits with the options (-Os) but can be compiled in 64 bits, -m64 is added to the CFLAGS variable in <certain makefiles in the project are listed>

My suggestion is to first try adding -m64 to your CFLAGS. If that doesn't work, delete the -m64 and replace it with -Os.

That is, first try having the following line:

CFLAGS = -g3 -Wall -Wextra -fPIC -DREPLICATION_ENABLED -DJOURNALING_ENABLED -m64

Then, from the command line, run

make clean

Followed by whatever make commands you use for your install.

If that doesn't work, change the line in question to

CFLAGS = -g3 -Wall -Wextra -fPIC -DREPLICATION_ENABLED -DJOURNALING_ENABLED -Os

Then make clean and the other make stuff.

If some of the C objects are 64-bit and some are 32-bit (I don't know if such a situation actually exists), you might have to do something different.

This worked in my case, details of which you can see here.

Please comment to let me know if it works for you.

Upvotes: 0

Clifford
Clifford

Reputation: 93476

You have misunderstood the error message. The error message is referring to the file get_next_line.o, not the makefile.

It is the linker (ld) that is reporting the error not make. The command that has failed is that for the target gnl.

Upvotes: 1

Jens Gustedt
Jens Gustedt

Reputation: 78923

This is not a make error by itself. It says

get_next_line.o: file not recognized: File format not recognized

so that is your problem. Somehow you managed to have a .o file in your directory that is corrupted. Remove it and things will go better.

Upvotes: 8

Related Questions