0

I'm trying to print a format string in NASN 64 (linux-fedora) but I'm getting an error that says "cannot find -lc" and "ld returned 1 exit status".

; ----------------------------------------------------------------------------------------
; Testing extern printf to print a format string.
; Linux-Fedora/.
; To assemble and run:
;
;     nasm -felf64 printf.asm 
;     gcc -static -o printf printf.o
; ----------------------------------------------------------------------------------------
;--------------------------------Varibles declaradas--------------------------------------
section .data                                                           
string                  db "The number is: %d", 10, 0                           
;-----------------------------------------------------------------------------------------
;-----------------------------------------------------------------------------------------
     section   .text
     extern printf
     global    main

main:
   mov rdi, string         ;the format string
   mov rsi, 10                 ;the argument (number 10)
   xor eax, eax                ;no vector in use
   call printf 

   ;exit(0)
   mov rax, 60                                         
   mov rdi, 0                                          
   syscall     

To get to print the string.

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
  • Does this answer your question? [Nasm - ld can't find printf](https://stackoverflow.com/questions/63492410/nasm-ld-cant-find-printf) – Kai Burghardt Nov 14 '22 at 23:16
  • @KaiBurghardt partly, let me edit. – Vladimir Curiel Nov 15 '22 at 03:44
  • `gcc -static -o printf printf.o` says it can't find `-lc`? Does Fedora not install a static version of libc (`libc.a`) by default? Once you do get it to link, see also [glibc scanf Segmentation faults when called from a function that doesn't align RSP](https://stackoverflow.com/q/51070716) and [Using printf in assembly leads to empty output when piping, but works on the terminal](https://stackoverflow.com/q/38379553) – Peter Cordes Nov 17 '22 at 03:35
  • @PeterCordes that worked, I had to do a lot of research to find how to install it properly. – Vladimir Curiel Nov 26 '22 at 16:42
  • You might want to post an answer to share with future readers what you had to install to get a static `libc.a` – Peter Cordes Nov 26 '22 at 16:43

0 Answers0