nasm-在macOS Mojave上无法将目标文件与ld链接 [英] nasm - Can't link object file with ld on macOS Mojave

查看:213
本文介绍了nasm-在macOS Mojave上无法将目标文件与ld链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试组装一个简单的Hello World,它在以前的macOS版本中可以正常工作:

I'm trying to assemble a simple Hello World, which worked fine in the previous macOS version:

        global   start
        section  .text
start:  mov      rax, 0x02000004
        mov      rdi, 1
        mov      rsi, msg
        mov      rdx, 13
        syscall
        mov      rax, 0x02000001
        xor      rdi, rdi
        syscall

        section  .data
msg:    db       "Hello world!", 10

然后像以前一样使用nasmld:

Then I use nasm and ld as I did before:

$ nasm -f macho64 hello.asm
$ ld hello.o -o hello

但是ld给我以下错误:

ld: warning: No version-min specified on command line
Undefined symbols for architecture x86_64:
  "_main", referenced from:
     implicit entry/start for main executable
ld: symbol(s) not found for inferred architecture x86_64

我尝试将start切换为_main,但是得到了以下信息:

I tried switching start to _main, but got the following:

ld: warning: No version-min specified on command line
ld: dynamic main executables must link with libSystem.dylib for inferred architecture x86_64

什至不知道那可能意味着什么.

Don't even know what that might mean.

推荐答案

ld需要-lSystem标志以防止其引发此错误.此外,还需要-macosx_version_min才能删除警告.使用ld的正确方法是:ld hello.o -o hello -macosx_version_min 10.13 -lSystem.

ld needs -lSystem flag to prevent it from throwing this error. Also it needs -macosx_version_min to remove the warning. The correct way of using ld would be: ld hello.o -o hello -macosx_version_min 10.13 -lSystem.

这篇关于nasm-在macOS Mojave上无法将目标文件与ld链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆