Gcc / usr / bin / ld编译错误

时间:2013-12-28 09:53:07

标签: gcc compilation ld

我做错时出现了这个错误

 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在表面pro 2上运行。

2 个答案:

答案 0 :(得分:2)

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

答案 1 :(得分:0)

如果您正在关注 this 教程,那么固定的 make 文件代码在下面适用于 Ubuntu 20

# $@ = 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