Editline Errors

358 views Asked by At

I am new to the C language and keep getting this error whenever I compile my C code with the command cc prompt.c. I get this error:

Undefined symbols for architecture x86_64:

"_add_history", referenced from:

  _main in prompt-66f61f.o

"_readline", referenced from:

  _main in prompt-66f61f.o

ld: symbol(s) not found for architecture x86_64

clang: error: linker command failed with exit code 1 (use -v to see invocation)

Here is my code :

#include <stdio.h>
#include <stdlib.h>

#include <editline/readline.h>


int main(int argc, char** argv) {

  /* Print Version and Exit Information */
  puts("Lispy Version 0.0.0.0.1");
  puts("Press Ctrl+c to Exit\n");

  /* In a never ending loop */
  while (1) {

    /* Output our prompt and get input */
    char* input = readline("lispy> ");

    /* Add input to history */
    add_history(input);

    /* Echo input back to user */    
    printf("No you're a %s\n", input);

    /* Free retrieved input */
    free(input);

  }

  return 0;
}

I am writing this program on a Macbook Air running OSX 10.10.3, if that helps.

I am just starting to learn the C language so don't judge me if this question is really simple, there were no results when I searched for it.

Any help would be greatly appreciated. Thanks!

1

There are 1 answers

4
Emil Laine On BEST ANSWER

You need to link your program with the editline library in order for your linker to find the definition of the readline and add_history functions.

You can do so by specifying the library with the -l flag in your compilation command:

cc prompt.c -ledit