【问题标题】:GCC compiler errorGCC 编译器错误
【发布时间】:2013-09-26 05:31:13
【问题描述】:
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 命令时出现此错误

/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

【问题讨论】:

  • hello.c 吗?您正在尝试编译 .h...

标签: c unix gcc linker


【解决方案1】:

你应该改变倒数第二行和最后一行 -

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

gcc -c -o hello.o hello.hgcc -c -o hello.o hello.c

这里的输入应该是一个c文件。

为了更多的理解,我建议你看看这个link

【讨论】:

    【解决方案2】:

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

    应该工作

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-10-07
      • 2016-11-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多