Compile assembler in nasm on mac os

两盒软妹~` 提交于 2020-06-10 05:52:41

问题


So, i write some instruction on asm, and compile them.

nasm -f macho test.asm

Now, nasm generate obj file, test.o

gcc test.o 

Returned next error:

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

in gcc line, i used -arch i386 (x86_64), returned same error.

Can anybody help? :)


回答1:


These commands work for me (OS X 10.12 x64):

nasm -f macho test.asm -DDARWIN
ld -o test test.o -arch i386 -lc -no_pie -macosx_version_min 10.12 -lSystem



回答2:


macho is a 32 bit format.
Try to use macho64 instead of macho. Complete line:

nasm -f macho64 test.asm



回答3:


Try to update your nasm version and use the following command:

/usr/local/bin/nasm -f macho64 ${file}
ld  -o ${file_path}/${file_base_name} -e _main ${file_path}/${file_base_name}.o
${file_path}/${file_base_name}


来源:https://stackoverflow.com/questions/14997777/compile-assembler-in-nasm-on-mac-os

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