2013-09-26 177 views
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 

當我使用make命令GCC編譯器錯誤

/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 
+6

是否有'hello.c'?您正在嘗試編譯'.h' ... – John3136

回答

4

你應該在倒數第二和最後一行改變我得到這個錯誤

此處輸入應該是一個c文件。

更多的瞭解,我建議你看看這個link

1

我認爲問題是,你嘗試編譯.h文件,即hello.h 應該hello.c中,你應該編譯

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 

應該工作