Nasm link for mac os x

I have some problems linking the nasm program for macos:

GLOBAL _start SEGMENT .text _start: mov ax, 5 mov bx, ax mov [a], ebx SEGMENT .data a DW 0 t2 DW 0 fry$ nasm -f elf test.asm fry$ ld -o test test.o -arch i386 ld: warning: in test.o, file was built for unsupported file format which is not the architecture being linked (i386) ld: could not find entry point "start" (perhaps missing crt1. fry$ nasm -f macho test.asm fry$ ld -o test test.o -arch i386 ld: could not find entry point "start" (perhaps missing crt1.o) 

Can anybody help me?

+4
source share
3 answers

Mac OS X cannot bind ELF objects. It only works with the Mach-O executable format. If you don't want to understand how to translate object files, you will probably be better off writing code that works with Mac OS X assembler.

Edit: as @Fry mentions in a comment below, you can make nasm port Mach-O objects. In this case, the problem is simple: release _ from _start in both places of the source file. The result is very good.

+7
source
 nasm -f macho test.asm ld -e _start -o test test.o 
+6
source

For people who need to stick with the elf format and develop on Mac, you need a cross-compiler ...

http://crossgcc.rts-software.org/doku.php?id=compiling_for_linux

Then you can continue something like this ...

 /usr/local/gcc-4.8.1-for-linux32/bin/i586-pc-linux-ld -m elf_i386 -T link.ld -o kernel kasm.o kc.o 
0
source

Source: https://habr.com/ru/post/1310912/


All Articles