开发者

link nasm program for mac os x

开发者 https://www.devze.com 2022-12-31 20:23 出处:网络
i have some problems with linking nasm program for macos: GLOBAL _start SEGMENT .text _start: mov ax, 5 mov bx, ax

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$ 开发者_如何学Cld -o test test.o -arch i386
ld: could not find entry point "start" (perhaps missing crt1.o)

can anyone help me?


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.


nasm -f macho test.asm

ld -e _start -o test test.o


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

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

Then you can proceed with something similar to 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

精彩评论

暂无评论...
验证码 换一张
取 消