Cannot find crtn.o, linking 32 bit code on 64 bit

2019-01-24 12:25发布

I'm attempting to assemble some 32-bit code using NASM and GCC on a 64-bit system. I use the following two commands

nasm -f elf32 -g -F stabs coc.asm
gcc -m32 -o coc coc.o

NASM appears to do fine, but LD complains:

/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.6.1/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.6.1/libgcc_s.so when searching for -lgcc_s
/usr/bin/ld: cannot find -lgcc_s
/usr/bin/ld: cannot find -lc
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.6.1/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.6.1/libgcc_s.so when searching for -lgcc_s
/usr/bin/ld: cannot find -lgcc_s
/usr/bin/ld: cannot find crtn.o: No such file or directory
collect2: ld returned 1 exit status

I'm running Ubuntu 11.10, and I checked and I'm pretty sure libc is installed.

标签: gcc 64bit nasm ld
3条回答
Animai°情兽
2楼-- · 2019-01-24 13:06

I had a very similar problem on ubuntu 11.10. See my question on SO about this. What helped for me, was linking the crt*.o to /lib/. After that I never had other problems with this issue. A bit more of a cludge, but for me it solved the problems.

查看更多
祖国的老花朵
3楼-- · 2019-01-24 13:09

You need to install gcc-multilib to get the proper 32-Bit lib

查看更多
Ridiculous、
4楼-- · 2019-01-24 13:23

You are not assembling, but linking an executable, which needs OS startup files.

It seems you don't have gcc-*-multilib installed, which contains the necessary files: http://packages.ubuntu.com/oneiric/amd64/gcc-4.6-multilib/filelist

查看更多
登录 后发表回答