GNU readline历史记录功能

web*_*kul 2 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
$
Run Code Online (Sandbox Code Playgroud)

oyl*_*gul 11

示例编译行是

g++ -o simple_rl{,.cpp} -lreadline
Run Code Online (Sandbox Code Playgroud)

你忘记添加-lreadline了吗?

  • 只是在这里添加一些东西,请注意`-lreadline`必须在命令行上需要它的源文件之后.我花了太多时间学习那种艰难的方式.;)请参阅http://gcc.gnu.org/onlinedocs/gcc/Link-Options.html了解原因. (3认同)