#include <stdlib.h>
#include <stdio.h> // This line should put before #include <editline.h>, or it will be failed to compile.
#include <editline.h>
int main(void)
{
char *p;
while ((p = readline("CLI> ")) != NULL) {
puts(p);
free(p);
}
return 0;
}
without #include <stdio.h>, the error message
$ g++ test.cc -I$HOME/mylib/include -L$HOME/mylib/lib -leditline
/mylib/include/editline.h:87:8: error: ‘FILE’ does not name a type
extern FILE *rl_instream; /* The stdio stream from which input is read. Defaults to stdin if NULL - Not supported yet! */
^~~~
In file included from test.cc:3:0:
mylib/include/editline.h:88:8: error: ‘FILE’ does not name a type
extern FILE *rl_outstream; /* The stdio stream to which output is flushed. Defaults to stdout if NULL - Not supported yet! */
test.cc: In function ‘int main()’:
test.cc:10:9: error: ‘puts’ was not declared in this scope
puts(p);
^~~~
without
#include <stdio.h>
, the error message