【问题标题】:GNU readline History featureGNU readline 历史功能
【发布时间】:2010-11-06 08:35:20
【问题描述】:

我将此代码用于我的 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
$

【问题讨论】:

  • 你能添加你用来编译它的确切命令吗?

标签: c unix shell readline


【解决方案1】:

用这个编译:

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

【讨论】:

    【解决方案2】:

    示例编译行是

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

    您是否忘记添加 -lreadline?

    【讨论】:

    • 只是在这里添加一点东西,注意-lreadline 必须在命令行中需要它的源文件之后。我花了太多时间以艰难的方式学习。 ;) 请参阅gcc.gnu.org/onlinedocs/gcc/Link-Options.html 了解原因。
    • Shanet,非常感谢你,我刚刚花费的时间比我承认自己发现我无法链接 readline 的时间还要多。如果您将问题发布到“为什么我不能链接 libreadline”,我会让我所有的朋友为您投票。
    猜你喜欢
    • 2015-03-10
    • 1970-01-01
    • 2012-09-13
    • 2012-05-14
    • 2013-11-21
    • 2013-12-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多