链接 Mac OS X 的 nasm 程序

发布于 2024-09-03 03:21:52 字数 564 浏览 7 评论 0原文

我在链接 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)

任何人都可以帮助我吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

一页 2024-09-10 03:21:52

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

编辑:正如 @Fry 在下面的评论中提到的,您可以使 nasm 输出 Mach-O 对象。在这种情况下,问题很简单 - 将源文件中两个位置的 _start 中的 _ 去掉。结果链接很好。

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.

几度春秋 2024-09-10 03:21:52
nasm -f macho test.asm

ld -e _start -o test test.o
nasm -f macho test.asm

ld -e _start -o test test.o
吲‖鸣 2024-09-10 03:21:52

对于需要坚持使用 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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文