Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

link nasm program for mac os x

Tags:

macos

linker

nasm

i have some problems with linking 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 anyone help me?

like image 681
Constantine Fry Avatar asked May 25 '10 22:05

Constantine Fry


People also ask

Can you use nasm on mac?

Most tutorials for nasm are written with Linux in mind, so you'll usually need to make a few adjustments to get things working on macOS. NASM Hello World for x86 and x86_64 Intel Mac OS is a great place to start, and the NASM Tutorial a great place to go from there (see section 'Using NASM on macOS').


1 Answers

The Mac OS X linker can't link ELF objects. It works only with the Mach-O executable format. Unless you want to figure out how to translate the object files, you'll probably be better off writing code that works with the Mac OS X assembler.

Edit: As @Fry mentions in the comment below, you can make nasm put out Mach-O objects. In that case, the problem is simple - take the _ off of _start in both places in your source file. The result links fine.

like image 161
Carl Norum Avatar answered Sep 24 '22 20:09

Carl Norum