2013-09-26 182 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 

应该工作