Hi,
stdio.h must be included before readline/readline.h in the following
program in order for it to compile on macOS. But the program can be
compiled on Linux when stdio.h is deleted.
Why is it so? Is it better to make it behave the same on Linux and
macOS? Thanks.
$ clang -Wall -I/usr/local/opt/readline/include
-L/usr/local/opt/readline/lib main.c -lreadline
#ifdef __APPLE__
#include <stdio.h>
#endif
#include <readline/readline.h>
#include <readline/history.h>
#include <stdlib.h>
int main(int argc, char **argv) {
while(1) {
char *line = readline("> ");
if(line == NULL) {
break;
} else if(strcmp(line, "q") == 0) {
free(line);
break;
}
if(strcmp(line, "") != 0) {
printf("%s\n", line);
add_history(line);
}
free(line);
}
return 0;
}
--
Regards,
Peng