0

I'm trying to use the GNU readline library in a program written in FASM. This is my assembly code:

format elf64

public _start

extrn readline

section ".text" executable
_start:
    push prompt
    call readline
    jmp  _start

section ".data"
    prompt db ">> ", 0

Then I compile and link it as follows:

$ fasm test.asm
$ ld -lreadline test.o -o test

However when I try to execute ./test bash gives me the following error message:

bash: ./test: No such file or directory

The test executable is present in the directory. What's wrong? Am I not linking the libreadline library correctly?

Aadit M Shah
  • 72,912
  • 30
  • 168
  • 299

1 Answers1

1

This happened to me once when I was on a 64-bit system compiling code for 32-bit. You have to install some additional 32-bit development tools and libraries (like an appropriate variant of libc) so that 32-bit binaries can be recognized as executable as well.

  • I'm using Ubuntu 13.04. Which packages do you believe I need to install? – Aadit M Shah Jun 09 '13 at 08:27
  • @AaditMShah Well, I don't know off of the top of my head, it's been a long I've used Ubuntu the last time. –  Jun 09 '13 at 09:26
  • I have seen this on straight 32-bit code. `ld`, by default, tried to use `/lib/ld-linux.so.1`as an interpreter/dynamic linker... which does not exist (on my system). (you can see this in a straight text-dump of the file) Solution is `ld -I/lib/ld-linux.so.2 ...` (`--dynamic-linker` is an alias for `-I`, if you like more typin'). Location on your system may be different, but I think this is what you've encountered. Confusing, aint it? May need to specify `-l readline` (and possibly `L path-to-libreadline` too) – Frank Kotler Jun 09 '13 at 13:29