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了吗?