I'm trying to implement rl_replace_line() in my code but when I try to compile it like that:
gcc -lreadline test.c -o test
I get this error message:
error: implicit declaration of function 'rl_replace_line' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
however I think I used the good header files? here is my code:
# include <stdio.h>
# include <readline/readline.h>
# include <readline/history.h>
# include <unistd.h>
# include <stdlib.h>
char *get_line()
{
char *line;
line = NULL;
if (line)
{
free(line);
line = NULL;
}
line = readline("Minishell>");
if (line)
add_history(line);
return (line);
}
void sig_handler(int signum)
{
if (signum == SIGINT)
{
printf("\n");
rl_on_new_line();
rl_replace_line("", 0);
rl_redisplay();
}
}
int main(void)
{
char *line;
signal(SIGINT, sig_handler);
line = get_line();
printf("%s\n", line);
}
I don't understand why it doesn't work, I hope you guys can help thanks!
I managed to solve my problem by including the correct path with:
-L.brew/opt/readline/lib
and -I.brew/opt/readline/include
now I compile like this and it's working:
gcc test.c -o test -lreadline -L .brew/opt/readline/lib -I .brew/opt/readline/include
I solve the issue by finding the libreadline.a with the command ==> find / -name libreadline.a 2> /dev/null.
The result is ==> /opt/homebrew/Cellar/readline/8.1.2/lib/libreadline.a
So I put the correct path for the compilation: -L libs -lft -L /opt/homebrew/Cellar/readline/8.1.2/lib -lreadline.
No this is working perfectly
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.