【问题标题】:link nasm program for mac os xmac os x 的链接 nasm 程序
【发布时间】:2011-02-23 22:20:04
【问题描述】:

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

谁能帮帮我?

【问题讨论】:

    标签: macos linker nasm


    【解决方案1】:

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

    编辑:正如@Fry 在下面的评论中提到的,您可以让nasm 输出 Mach-O 对象。在这种情况下,问题很简单——在源文件的两个位置都将__start 分开。结果链接正常。

    【讨论】:

    • fry$ nasm -f macho test.asm frog$ ld -o test test.o -arch i386 ld: 找不到入口点“start”(可能缺少 crt1.o)
    • @Fry,编辑了您需要的答案。另外 - 去接受一些答案。
    【解决方案2】:
    nasm -f macho test.asm
    
    ld -e _start -o test test.o
    

    【讨论】:

      【解决方案3】:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-01-05
        • 2014-10-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-12-03
        • 1970-01-01
        相关资源
        最近更新 更多