【问题标题】:Gcc /usr/bin/ld compiler errorgcc /usr/bin/ld 编译器错误
【发布时间】:2013-12-28 09:53:06
【问题描述】:

我在制作时遇到了这个错误

 gcc -o tests/simple_test tests/simple_test.o -L. libtraceback.a -Wall -Werror -gdwarf-2 -O0 -m32 -fno-stack-protector -fno-omit-frame-pointer -Itraceback/ -mpreferred-stack-boundary=2   -static
/usr/bin/ld: cannot find crt1.o: No such file or directory
/usr/bin/ld: cannot find crti.o: No such file or directory
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.8/libgcc.a when searching for -lgcc
/usr/bin/ld: cannot find -lgcc
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.8/libgcc_eh.a when searching for -lgcc_eh
/usr/bin/ld: cannot find -lgcc_eh
/usr/bin/ld: cannot find -lc
collect2: error: ld returned 1 exit status

我读了一篇文章并尝试了

sudo ln -s /usr/lib/x86_64-linux-gnu /usr/lib64

但是没有用,有什么原因吗?

我使用运行 64 位 ubuntu 13.10 的 vmware 在 Surface Pro 2 上运行。

【问题讨论】:

  • 看起来您的编译器配置错误。我会尝试重新安装它。
  • 我试过 sudo apt-get install --reinstall gcc
  • 重新安装后出现同样的错误
  • 看起来您正在尝试构建一段 32 位代码,而它只查看 6 位库 - -m32 表明了这一点。猜测您缺少 32 位库。如果你真的想制作 32 位代码,那么你需要确保你已经安装了相关的 32 位库。上次我这样做所需的命令是apt-get install ia32-libs
  • 有道理,我是不是必须更改 Makefile 之类的?

标签: gcc compilation ld


【解决方案1】:

如果您没有任何特殊原因要在 64 位机器上构建 32 位应用程序,请不要使用选项 -m32。

【讨论】:

    【解决方案2】:

    如果您正在关注this 教程,那么在 Ubuntu 20 上修复的 make 文件代码如下所示

    # $@ = target file
    # $< = first dependency
    # $^ = all dependencies
    
    # First rule is the one executed when no parameters are fed to the Makefile
    all: run
    
    kernel.bin: kernel-entry.o kernel.o
        ld -m elf_i386 -o $@ -Ttext 0x1000 $^ --oformat binary --entry main
    
    kernel-entry.o: kernel-entry.asm
        nasm $< -f elf -o $@
    
    kernel.o: kernel.c
        gcc -m32 -ffreestanding -c $< -o $@ -fno-pie
    
    mbr.bin: mbr.asm
        nasm $< -f bin -o $@
    
    os-image.bin: mbr.bin kernel.bin
        cat $^ > $@
    
    run: os-image.bin
        qemu-system-i386 -fda $<
    
    clean:
        $(RM) *.bin *.o *.dis
    

    运行make文件

    make run
    

    清理所有输出文件

    make clean
    

    【讨论】:

      猜你喜欢
      • 2023-01-07
      • 1970-01-01
      • 1970-01-01
      • 2014-08-17
      • 1970-01-01
      • 1970-01-01
      • 2013-01-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多