链接 Mac OS X 的 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 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
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.对于需要坚持使用 elf 格式并在 Mac 上进行开发的人来说,您需要一个交叉编译器...
http://crossgcc.rts-software.org/doku.php?id=compiling_for_linux
然后你可以继续执行类似的操作...
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...