gpt4 book ai didi

c - 编辑行错误

转载 作者:行者123 更新时间:2023-11-30 15:19:21 24 4
gpt4 key购买 nike

我是 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;
}

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

我刚刚开始学习C语言,所以不要判断我这个问题是否很简单,我搜索时没有结果。

任何帮助将不胜感激。谢谢!

最佳答案

您需要将程序与 editline 库链接,以便链接器找到 readlineadd_history 函数的定义。

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

cc prompt.c -ledit

关于c - 编辑行错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30721934/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com