小编Fre*_*ers的帖子

将使用 printf 和 ld 的程序链接起来?

在 x86-64 Ubuntu 上使用 NASMundefined reference to _printf构建定义自己_start而不是的汇编程序时,我得到了一个main

构建命令:

   nasm -f elf64 hello.asm
   ld -s -o hello hello.o
   hello.o: In function `_start':
   hello.asm:(.text+0x1a): undefined reference to `_printf'
   MakeFile:4: recipe for target 'compile' failed
   make: *** [compile] Error 1
Run Code Online (Sandbox Code Playgroud)

nasm 来源:

extern _printf

section .text
    global _start
_start:
    mov rdi, format     ; argument #1
    mov rsi, message    ; argument #2
    mov rax, 0
  call _printf            ; call printf

    mov rax, 0
    ret                 ; return 0

section …
Run Code Online (Sandbox Code Playgroud)

linux assembly linker libc ld

4
推荐指数
1
解决办法
1974
查看次数

标签 统计

assembly ×1

ld ×1

libc ×1

linker ×1

linux ×1