Reputation: 65
i am trying to run this code but the compiler fails : undefined reference to ' readline ' and undefined reference to ' add_history ' .I am using CodeBlocks .This is my code :
#include <stdio.h>
#include <stdlib.h>
#include <readline/readline.h>
#include <readline/history.h>
int main()
{
char *buf;
while((buf = readline("\n >> "))!=NULL)
{
if (strcmp(buf,"quit")==0)
break;
printf("[%s]\n",buf);
if (buf[0]!=0)
add_history(buf);
}
free(buf);
return 0;
}
Upvotes: 2
Views: 2232
Reputation: 53006
Ok, just ensure the development files for readline are installed for which you need to run this as the root user
# apt-get install libreadline-dev
as someone mentioned in the comments.
Next, you go to the Project->Build Options
menu and a dialog pops up
then go to the Linker Settings
tab
now just click the Add
button, and type readline
in the dialog that pops up
click Ok
, and try building now, it should work.
Upvotes: 1