87

I have included:

#include "stdio.h"    
#include <readline/readline.h>
#include <readline/history.h>

and my compiler includes the flag

-lreadline

but I am still receiving the error message:

fatal error: 'readline/readline.h' file not found

I am trying to use the function, readline();

Defined in more detail here: http://linux.die.net/man/3/readline

Hans Lub
  • 5,513
  • 1
  • 23
  • 43
timeshift117
  • 1,720
  • 2
  • 18
  • 21
  • What os/version are you using? – Tim Apr 15 '14 at 13:27
  • What is the path that your compiler looks in for include files? (Typically, it includes `/usr/include`). Does `readline/readline.h` exist in that path? (eg, `/usr/include/readline/readline.h`). If not, add the correct path via `-I`. (eg, if you have installed readline in /usr/local, add `-I/usr/local/include` to the compiler invocation.) – William Pursell Apr 15 '14 at 13:28
  • @TimCastelijns 2013 x86_64 x86_64 x86_64 GNU/Linux – timeshift117 Apr 15 '14 at 13:33
  • @WilliamPursell I can't include any local files that aren't reasonably platform independent as this has to be used on other systems, on which I won't be able to control what is installed. – timeshift117 Apr 15 '14 at 13:34
  • Actually, I think you might be right @WilliamPursell, thanks – timeshift117 Apr 15 '14 at 13:38
  • @timeshift117: If you can't assume that `readline` is installed on all the systems where your software runs, then you can't use `readline` (unless you can manage to incorporate the `readline` code into your program). – Keith Thompson Apr 15 '14 at 14:38

2 Answers2

195

You reference a Linux distribution, so you need to install the readline development libraries

On Debian based platforms, like Ubuntu, you can run:

sudo apt-get install libreadline-dev 

and that should install the correct headers in the correct places,.

If you use a platform with yum, like SUSE, then the command should be:

yum install readline-devel
Mike
  • 47,263
  • 29
  • 113
  • 177
  • 2
    Thanks this worked, but when I removed the -lreadline it stopped working, so I had to put that back in. I am using clang to compile, not sure if that's the reason I had to leave it in. I'll accept your answer when the min. time is up. – timeshift117 Apr 15 '14 at 13:45
  • 1
    @timeshift117 - you're quite right it does need to be in there. Just to *find* the header files you don't need to link anything, but to *use* the function you need to link the readline library. It's pointless to include but not use the headers so I removed that from the answer – Mike Apr 15 '14 at 13:52
  • Can You tell me what -dev means ?? – Suraj Jain Feb 25 '17 at 04:36
  • 1
    @SurajJain **-dev** or **-devel** suffixes means sources and headers for DEVelopers. Packages without **dev** contains compiled binaries only. – DenisKolodin Feb 27 '17 at 10:51
3

This command helped me on linux mint when i had exact same problem

gcc filename.c -L/usr/include -lreadline -o filename

You could use alias if you compile it many times Forexample:

alias compilefilename='gcc filename.c -L/usr/include -lreadline -o filename'
λjk.jk
  • 127
  • 1
  • 12