nasm and gcc: 32 bit linking failed (64 bit Mac OS X)

被刻印的时光 ゝ 提交于 2020-01-06 03:03:09

问题


I've just compiled a assembley file with nasm this way:

$ nasm -f elf somefile.asm -o somefile.o

After that I want to link somefile.o to a programm with gcc

$ gcc -m32 somefile.o -o someprogramm

But linking the file prints the following error:

ld: warning: ignoring file somefile.o, file was built for unsupported file format which is 
not the architecture being linked (i386)
Undefined symbols for architecture i386:
  "_main", referenced from:
     start in crt1.10.6.o
ld: symbol(s) not found for architecture i386
collect2: ld returned 1 exit status

回答1:


The problem you're having is that you're creating a 32-bit Linux(ELF) object file which isn't compatible with the Mac OS X object format. Try switching '-f elf' to '-f macho32'.




回答2:


After a time I decided to use Linux for this kind of programms, because it has more flexibility. You can use Linux on a virtual machine like Virtual Box.



来源:https://stackoverflow.com/questions/10726434/nasm-and-gcc-32-bit-linking-failed-64-bit-mac-os-x

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!