Macos 用于mac os x的link nasm程序

Macos 用于mac os x的link nasm程序,macos,linker,nasm,Macos,Linker,Nasm,我在链接macos的nasm程序时遇到一些问题: 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 unsupp

我在链接macos的nasm程序时遇到一些问题:

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)

有人能帮我吗?

Mac OS X链接器无法链接ELF对象。它仅适用于Mach-O可执行格式。除非您想知道如何翻译目标文件,否则最好编写与MacOSX汇编程序一起工作的代码


编辑:正如@Fry在下面的评论中提到的,您可以制作
nasm
put-out Mach-O对象。在这种情况下,问题很简单-在源文件的两个位置都将
\u开始
\u关闭。结果链接很好。

对于需要坚持elf格式并在mac上开发的人,您需要一个交叉编译器

nasm -f macho test.asm

ld -e _start -o test test.o

然后你可以继续做类似的事情

/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

fry$nasm-f macho test.asm fry$ld-o test.o-arch i386 ld:找不到入口点“start”(可能缺少crt1.o)@fry,使用您需要的答案编辑。同时,去接受一些答案。