我为我的外壳实现了历史记录,但出现了错误 [英] I implement history for my shell and i have a error

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

问题描述

我使用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

推荐答案

转到GNU Readline库 [
Go to The GNU Readline Library[^], where everything is explained.


我假设已经安装了库和头文件.否则,您将收到有关缺少包含文件的编译器错误.

编译和单行链接时,必须在源文件之后传递库:
I assume that the library and the header files has been installed. Otherwise you would get a compiler error about missing include files.

You must pass the libraries after the source files when compiling and linking with a single line:
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


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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆