0
main: main.o print.o credits.o hello.o
        gcc -o main main.o print.o credits.o hello.o

main.o: main.c hello.h
        gcc -c -o main.o main.c

print.o: print.c hello.h
        gcc -c -o print.o print.c

credits.o: credits.c hello.h
        gcc -c -o credits.o credits.c

hello.o: hello.h
        gcc -c -o hello.o hello.h

I get this error when I use the make command

/usr/bin/ld:hello.o: file format not recognized; treating as linker script
/usr/bin/ld:hello.o:1: syntax error
collect2: error: ld returned 1 exit status
make: *** [main] Error 1
1
  • 6
    Is there a hello.c ? You are trying to compile the .h... Commented Sep 26, 2013 at 5:33

2 Answers 2

4

You should change the second last and last line -

hello.o: hello.h to hello.o: hello.c hello.h

gcc -c -o hello.o hello.h to gcc -c -o hello.o hello.c

The input here should be a c file.

For more understanding I would recommend you look at this link

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

Comments

1

I think the problem is that you are trying to compile a .h file,ie hello.h It should be hello.c that you should be compiling

main: main.o print.o credits.o hello.o
    gcc -o main main.o print.o credits.o hello.o

main.o: main.c hello.h
    gcc -c -o main.o main.c

print.o: print.c hello.h
    gcc -c -o print.o print.c

credits.o: credits.c hello.h
    gcc -c -o credits.o credits.c

hello.o: hello.c hello.h
    gcc -c -o hello.o hello.c

Should Work

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.