简体   繁体   English

GCC编译器错误

[英]GCC compiler error

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 使用make命令时出现此错误

/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

You should change the second last and last line - 您应该更改倒数第二行-

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

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

The input here should be ac file. 此处的输入应为ac文件。

For more understanding I would recommend you look at this link 要了解更多信息,建议您查看此链接

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 我认为问题是您正在尝试编译.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

Should Work 应该管用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM