【问题标题】:readline in C doesn't workC中的readline不起作用
【发布时间】:2012-12-28 03:13:25
【问题描述】:

我以前从未遇到过这样的问题。我在 Mac 上编写简单的 C 程序并像往常一样使用 gcc 编译。

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <readline/readline.h>
#include <readline/history.h>

#define MAXLINES 5

char *lineptr[MAXLINES];
void writel(char *lineptr[], int nlines);
void quicksort(char *lineptr[], int left, int right);
void swap(char *v[], int i, int j);

/* sort input lines */
int main() {
  int nlines; /* number of lines to read */
  int i = 0;

  /* saves lines in the array lineptr */
  while (i < MAXLINES) {
    lineptr[i] = readline("Enter a line: \n");
    i++;
  }

  quicksort(lineptr, 0, MAXLINES-1);
  writel(lineptr, MAXLINES);
  return 0;
}

似乎是 readline 造成了麻烦。一旦我注释掉lineptr[i] = readline("Enter a line: \n");,它就编译好了。但我不明白这里的 readline 有什么问题......错误是:

架构 x86_64 的未定义符号: “_readline”,引用自: _main 在 cckHOwOt.o ld:未找到架构 x86_64 的符号

感谢任何可以提供建议的人。 谢谢!

【问题讨论】:

  • 这是某种构建配置问题——与 readline 本身并没有真正关联,而是与链接的 I/O 库有关。
  • em,谢谢你的链接。

标签: c


【解决方案1】:

使用-lreadline 编译您的代码。当然,您还需要在系统上安装 readline-devel 软件包。

【讨论】:

    猜你喜欢
    • 2012-02-15
    • 1970-01-01
    • 2012-01-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-25
    相关资源
    最近更新 更多