Angelo
Angelo

Reputation: 65

C- Readline() undefined reference

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

Answers (1)

Iharob Al Asimi
Iharob Al Asimi

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 Build Options Dialog

then go to the Linker Settings tabLinker Settings Tab

now just click the Add button, and type readline in the dialog that pops up enter image description here

click Ok, and try building now, it should work.

Upvotes: 1

Related Questions