5

我在为 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)

谁能帮我?

4

3 回答 3

7

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

编辑:正如@Fry 在下面的评论中提到的,您可以制作nasm出 Mach-O 对象。在这种情况下,问题很简单——在源文件的两个地方都去掉__start结果链接正常。

于 2010-05-25T22:13:13.120 回答
6
nasm -f macho test.asm

ld -e _start -o test test.o
于 2010-12-07T00:46:04.947 回答
1

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

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

然后你可以继续进行类似的事情......

/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
于 2015-12-03T16:46:36.617 回答