Include “stdio.h” before Readline library header files

I install Readline library and write a simple program to play with it:

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

int main(void)
{
    char *line_read = readline (">>  ");
    if (line_read && *line_read)
    {
        add_history (line_read);
    }
    ......
}

Build it will generate following errors:

In file included from /usr/include/readline/readline.h:35:0,
                 from readline.c:3:
/usr/include/readline/rltypedefs.h:71:28: error: unknown type name 'FILE'
 typedef int rl_getc_func_t PARAMS((FILE *));
                            ^
/usr/include/readline/readline.h:429:20: error: unknown type name 'FILE'
 extern int rl_getc PARAMS((FILE *));
                    ^
In file included from readline.c:3:0:
/usr/include/readline/readline.h:558:8: error: unknown type name 'FILE'
 extern FILE *rl_instream;
        ^~~~
/usr/include/readline/readline.h:559:8: error: unknown type name 'FILE'
 extern FILE *rl_outstream;
        ^~~~
/usr/include/readline/readline.h:588:8: error: unknown type name 'rl_getc_func_t'
 extern rl_getc_func_t *rl_getc_function;
        ^~~~~~~~~~~~~~
/usr/include/readline/readline.h:917:3: error: unknown type name 'FILE'
   FILE *inf;
   ^~~~
/usr/include/readline/readline.h:918:3: error: unknown type name 'FILE'
   FILE *outf;

The solution is including <stdio.h> before Readline library’s header files:

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

One thought on “Include “stdio.h” before Readline library header files”

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.