存档没有索引;运行 ranlib 添加一个(当在 Linux 上链接包含 MachO64 目标文件的 .a 时)

AMA*_*OSS 5 c linux assembly static-libraries unix-ar

我尝试创建一个库并对其进行测试,但发生了错误。
错误代码:

./libasm.a: error adding symbols: Archive has no index; run ranlib to add one
collect2: error: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)

我是这样编译的。
nasm -f macho64 ft_strlen.s -o ft_strlen.o
ar rcs libasm.a ft_strlen.o
ranlib libasm.a
gcc main.c libasm.a
下面是源文件

;ft_strlen.s
segment .text
    global ft_strlen

ft_strlen:
    mov     rax, 0
    jmp     count

count:
    cmp     BYTE [rdi + rax], 0
    je      exit
    inc     rax
    jmp     count

exit:
    ret
Run Code Online (Sandbox Code Playgroud)
./libasm.a: error adding symbols: Archive has no index; run ranlib to add one
collect2: error: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)

我正在使用安装在 wsl 上的 ubuntu。
我究竟做错了什么?

AMA*_*OSS 3

为基于 Linux 的操作系统(或者更准确地说,ELF64 系统)生成目标文件nasm -f elf64 ft_strlen.s -o ft_strlen.o

有关详细信息,nasm -hf请参阅所有有效的输出格式nasm -f

小提示:ranlib不需要命令,因为ar s已经对库进行了索引。