gpt4 book ai didi

macos - nasm - 无法在 macOS Mojave 上将目标文件与 ld 链接

转载 作者:行者123 更新时间:2023-12-03 01:02:16 26 4
gpt4 key购买 nike

我正在尝试组装一个简单的 Hello World,它在以前的 macOS 版本中运行良好:

        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:

$ 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,但得到以下结果:

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

甚至不知道这意味着什么。

最佳答案

ld需求-lSystem标志以防止它抛出此错误。它还需要 -macosx_version_min删除警告。正确的使用方法ld将是:ld hello.o -o hello -macosx_version_min 10.13 -lSystem .

已更新,在 macOS 11 及更高版本上,您需要传递 -L/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib以便它找到 -lSystem库正确。您可以使用-L$(xcode-select -p)/SDKs/MacOSX.sdk/usr/lib如果需要,动态评估正确的路径。

关于macos - nasm - 无法在 macOS Mojave 上将目标文件与 ld 链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52830484/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com