Linker 已解决:使用ld.lld链接器链接nasm

Linker 已解决:使用ld.lld链接器链接nasm,linker,llvm,nasm,libc,Linker,Llvm,Nasm,Libc,我有main.s文件 extern printf extern exit section .data fmt: db "hi!", 0xa section .text global _start _start: mov rax, 0 mov rdi, fmt call printf call exit 编译并运行 $ yasm -f elf64 main.s -o main.o $ ld.lld main.o -o main --dynamic-li

我有main.s文件

extern printf
extern exit

section .data
  fmt: db "hi!", 0xa

section .text
global _start
_start:
  mov rax, 0
  mov rdi, fmt
  call printf
  call exit
编译并运行

$ yasm -f elf64 main.s -o main.o
$ ld.lld main.o -o main --dynamic-linker /lib/ld-linux-x86-64.so.2
$ ./main
但我得到了:
ld.lld:错误:未定义符号:printf
ld.lld:错误:未定义符号:退出


ld.lld没有像ld linker那样的-lc选项。

只需使用:-L/lib选项告诉链接器在哪里可以找到libc

ld.lld main.o --dynamic-linker /lib/ld-linux-x86-64.so.2 -o main -L/lib -lc