【问题标题】:Undefined reference to 'readline' - C未定义对“readline”的引用 - C
【发布时间】:2016-05-25 03:34:48
【问题描述】:

我得到的错误:

undefined reference to `readline'

这是我的生成文件:

all: stest stestdebug

stest: stest.o struct.o
    gcc -g stest.o struct.o -lreadline -lncurses -o stest

stest.o: stest.c struct.h
    gcc -g -c stest.c 

stestdebug: stestdebug.o struct.o
    gcc -g stestdebug.o struct.o -o stestdebug

stestdebug.o: stest.c struct.h
    gcc -g -c stest.c -o stestdebug.o 

struct.o: struct.c struct.h
    gcc -g -c -DDEBUG struct.c 

clean:
    rm -f *.o stest stestdebug

docs:
    doxygen
    chmod a+r html/*
    cp -p html/* ~/public_html/cs2303assig4

我已经为 readline 导入了所有必要的库,但仍然出现此错误。

这是我调用它的代码:

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

void requestInput() {
  printf("Please fill out all prompts to create a new emplyoee.\n");
  char *name = readline("Name:");
}

【问题讨论】:

  • 你有 stest 目标的 -lreadline 但没有 stestdebug 目标。
  • 这要么是duplicate,要么是错字;可能两者兼而有之。

标签: c makefile readline undefined-reference


【解决方案1】:

您没有在主可执行文件中链接到它们。

将您的库放在一个变量中,并在您的测试目标和普通目标中使用它们。

查看 LDFLAGS。

【讨论】:

    猜你喜欢
    • 2015-02-14
    • 1970-01-01
    • 2019-06-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多