Author Topic: [solved] how to link sdl2 to assembly program using nasm + ld?  (Read 5669 times)

Offline mmk213

  • Jr. Member
  • *
  • Posts: 8
hi, i am using slackware linux, i am trying to compile this basic program, but i cannot start the executable when i compile it, it has something to do with linking the sdl2 library but i am new to this, not sure how to procede

my file (sdl.asm) is:
Code: [Select]
section .text
extern SDL_Init
global _start
_start:
  mov rdi, 0x20
  call SDL_Init

  xor eax, eax
  add al, 0x3C
  syscall

so i'm trying to compile this basic code with
Code: [Select]
nasm -f elf64 sdl.asm -o sdl.o
ld sdl.o -o sdl -lSDL2

but when i start the file i get
Code: [Select]
bash: ./sdl: No such file or directory

"file sdl" gets me:
Code: [Select]
sdl: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib/ld64.so.1, not stripped

« Last Edit: June 27, 2017, 04:58:25 AM by mmk213 »

Offline mmk213

  • Jr. Member
  • *
  • Posts: 8
Re: how to link sdl2 to assembly program using nasm + ld?
« Reply #1 on: June 27, 2017, 04:57:41 AM »
hm, i managed to get it running, not really sure why though

Code: [Select]
ld -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o sdl sdl.o -lSDL2

this gave me a working executable, but i dont know why is this ld-linux-x86-64.so.2 link option needed.. i wil marked it solved

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: [solved] how to link sdl2 to assembly program using nasm + ld?
« Reply #2 on: June 27, 2017, 05:38:23 AM »
32-bit ld does the same thing - the default dynamic linker does not exist. I don't know why. If you want to save some typing, "-I" is an alias for "-dynamic-linker". Good job figuring it out. That "no such file or directory" - when you can see it right there - is pretty confusing!

Best,
Frank