89

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

6
  • What os/version are you using?
    – Tim
    Commented Apr 15, 2014 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.) Commented Apr 15, 2014 at 13:28
  • @TimCastelijns 2013 x86_64 x86_64 x86_64 GNU/Linux Commented Apr 15, 2014 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. Commented Apr 15, 2014 at 13:34
  • Actually, I think you might be right @WilliamPursell, thanks Commented Apr 15, 2014 at 13:38

2 Answers 2

205

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
4
  • 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. Commented Apr 15, 2014 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
    Commented Apr 15, 2014 at 13:52
  • Can You tell me what -dev means ??
    – Suraj Jain
    Commented Feb 25, 2017 at 4:36
  • 1
    @SurajJain -dev or -devel suffixes means sources and headers for DEVelopers. Packages without dev contains compiled binaries only. Commented Feb 27, 2017 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'
1
  • 1
    The -L option is for specifying library directories, not header files.
    – stark
    Commented Sep 24, 2022 at 10:47

Not the answer you're looking for? Browse other questions tagged or ask your own question.