troglobit / editline

A small replacement for GNU readline() for UNIX
https://troglobit.com/projects/editline/
Other
281 stars 58 forks source link

Example Step 2 needs header file <stdio.h> #41

Closed byteroll closed 4 years ago

byteroll commented 4 years ago
#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);
         ^~~~
byteroll commented 4 years ago

And my system is Ubuntu 18.04, build system is gcc version 7.5.0