GNU readline历史记录功能

时间:2009-06-27 10:26:41

标签: c unix shell readline

我在shell中使用此代码作为历史记录功能: http://cc.byexamples.com/20080613/gnu-readline-how-to-keep-a-history-list-of-entered-command-lines/ 但是当我用gcc编译它时,我收到了这个错误

$ gcc filename.c
/tmp/ccay2CgM.o: In function `main':
rl.c:(.text+0x9): undefined reference to `rl_abort'
rl.c:(.text+0x13): undefined reference to `rl_bind_key'
rl.c:(.text+0x1d): undefined reference to `readline'
rl.c:(.text+0x61): undefined reference to `add_history'
collect2: ld returned 1 exit status
$

2 个答案:

答案 0 :(得分:11)

示例编译行是

g++ -o simple_rl{,.cpp} -lreadline

您是否忘记添加-lreadline?

答案 1 :(得分:2)

编译:

gcc -lreadline -lncurses -o simple_rl{,.cpp}