编辑行错误

Editline Errors

我是 C 语言的新手,每当我使用命令 cc prompt.c 编译我的 C 代码时,都会收到此错误。我收到此错误:

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)

这是我的代码:

#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;
}

我正在 Macbook Air 运行 OSX 10.10.3 上编写此程序,如果有帮助的话。

我才刚开始学C语言,请不要看我这道题是不是很简单,我一搜就没有结果

如有任何帮助,我们将不胜感激。谢谢!

您需要 link 您的程序使用 editline 库,以便您的 link 儿找到 readlineadd_history 的定义函数。

您可以通过在编译命令中使用 -l 标志指定库来实现:

cc prompt.c -ledit