我正在尝试使用 64 位 Mac OS X Lion 运行基本程序集文件,使用默认情况下随 Xcode 安装的 nasm 和 ld。
我已经编写了一个汇编文件,它打印一个字符,并使用 nasm 构建它。
nasm -f elf -o program.o main.asm
但是,当我将它与 ld 链接时,它会失败并出现很多错误/警告:
ld -o program program.o
ld: warning: -arch not specified
ld: warning: -macosx_version_min not specificed, assuming 10.7
ld: warning: ignoring file program.o, file was built for unsupported file format which is not the architecture being linked (x86_64)
ld: warning: symbol dyld_stub_binder not found, normally in libSystem.dylib
ld: entry point (start) undefined. Usually in crt1.o for inferred architecture x86_64
所以,我试图纠正其中的一些问题,但一无所获。
这是我尝试过的一件事:
ld -arch i386 -e _start -o program program.o
我认为这会起作用,但我错了。
您如何使目标文件成为 nasm 和 ld 同意的兼容架构?
另外,您将如何定义程序中的入口点(现在我正在使用global _start
in .section text
,在上面_start
,这似乎并没有多大用处。)
对于如何使用 ld 成功地将目标文件链接到二进制文件,我有点困惑,我想我只是遗漏了一些让他们同意的代码(或 nasm 或 ld 的参数)。
任何帮助表示赞赏。