本文介绍了我为我的外壳实现了历史记录,但出现了错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用readline实现历史记录,但出现错误

来自用户的代码:

I implement history with readline and I have an error

code from user:

#include<readline readline.h="">
#include<readline history.h="">
int main(){
char *line4;
while(1)
{
line4 = readline("Commander Shepard >");
	add_history(line4);
}
}



我尝试过的事情:



What I have tried:

p.c:(.text+0x1478): undefined reference to `readline'
p.c:(.text+0x148e): undefined reference to `add_history'
Compailing with -lreadline or -readline I have another error
gcc: error: p: No such file or directory

推荐答案


gcc -Wall source-file.cpp -lreadline -o program-name


常见的gcc选项顺序如下:


  • 编译器选项,例如优化和包含路径
  • 源文件
  • 链接器选项,例如库和库路径
  • Output

  • The common gcc option sequence is then:


    • Compiler options like optimising and include pathes
    • Source files
    • Linker options like libraries and library pathes
    • Output
    • gcc -Wall -c source-file.cpp
      gcc source-file.o -lreadline -o program-name


      这篇关于我为我的外壳实现了历史记录,但出现了错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 13:31