Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compile assembler in nasm on mac os

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? :)

like image 355
Aleeewka Avatar asked Jan 22 '26 21:01

Aleeewka


2 Answers

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
like image 119
theluckyemil Avatar answered Jan 24 '26 15:01

theluckyemil


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

nasm -f macho64 test.asm
like image 28
qwertz Avatar answered Jan 24 '26 15:01

qwertz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!