Reputation: 17
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
Upvotes: 0
Views: 317
Reputation: 955
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
Upvotes: 4
Reputation: 1310
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
Upvotes: 1