无法在 OpenBSD 上使用 editline 进行编译

标签 c freebsd bsd openbsd editline

我想我必须安装 editline (libedit?) 库,但我在哪里可以为 OpenBSD 获得它?代码在 PC-BSD 上编译得很好,但在 OpenBSD 上我得到这个错误

implicit declaration of rl_bind_key

是editline库没有找到。我试着用谷歌搜索在哪里可以找到它的 OpenBSD,但没有找到。你能帮助我吗?我使用的 header 是

#define _XOPEN_SOURCE 500

#include <sys/stat.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <signal.h>
#include <sys/wait.h>
#include "openshell.h"
#include "errors.h"
#include <errno.h>
#include <locale.h>
#include <editline/readline.h>

生成文件

CC = gcc
GIT_VERSION := $(shell git describe --abbrev=4 --dirty --always --tags)
CFLAGS := $(CFLAGS) -pedantic -std=c99 -Wall -O3 -ledit -g -DVERSION=\"$(GIT_VERSION)\"

shell: main.o
    $(CC) -o shell main.o errors.c util.c pipeline.c -ledit

main.o: main.c errors.c util.c

.PHONY: clean
clean:
    rm -f *.o

这是有问题的代码

int exec_program(const char *name) {
    FILE *fp;
    int r = 0;
    char *input, shell_prompt[100];
    if (sourceCount >= MAX_SOURCE) {
        fprintf(stderr, "Too many source files\n");
        return 1;
    }
    fp = stdin;
    if (name) {
        fp = fopen(name, "r");

        if (fp == NULL) {
            perror(name);

            return 1;
        }
    }
    sourcefiles[sourceCount++] = fp;
    setlocale(LC_CTYPE, "");
    /*Configure readline to auto-complete paths when the tab key is hit.*/
    rl_bind_key('\t', rl_complete);
    stifle_history(7);
    for (; ;) {
        /* Create prompt string from user name and current working directory.*/
        snprintf(shell_prompt, sizeof(shell_prompt), "%s:%s $ ", getenv("USER"), getcwd(NULL, 1024));
        // Display prompt and read input (NB: input must be freed after use)...
        input = readline(shell_prompt);
        // Check for EOF.
        if (!input)
            break;
        add_history(input);
        r = command(input);
        free(input);
    }
    return r;
}

如果我运行 locate editline 然后它找到并更改 Makefile 并得到一个新错误 undefined reference to tgetnum 根据 google 看来我必须链接到ncurses库。现在它编译了。新的 Makefile 是:

CC = gcc
GIT_VERSION := $(shell git describe --abbrev=4 --dirty --always --tags)
CFLAGS := $(CFLAGS) -L/usr/local/include/ -L/usr/include -pedantic -std=c99 -Wall -O3 -g -DVERSION=\"$(GIT_VERSION)\" -ledit -lncurses

LDIRS = -L/usr/local/lib -L/usr/lib
LIBS = -ledit lncurses -lcurses

shell: main.o
    $(CC) -o shell main.o errors.c util.c pipeline.c -ledit -lncurses -lcurses

main.o: main.c errors.c util.c

.PHONY: clean
clean:
    rm -f *.o

最佳答案

检查在哪里可以找到 editline/readline.h(例如使用 locate)。

如果它在 /usr/local/include 中,您应该将其添加到 Makefile 中的 CFLAGS 中;

CFLAGS := $(CFLAGS) -I/usr/local/include -pedantic -std=c99 -Wall -O3 -g -DVERSION=\"$(GIT_VERSION)\"
LDIRS = -L/usr/local/lib
LIBS = -ledit

SRCS= main.c errors.c util.c pipeline.c
OBJS= $(SRCS:.c=.o)

shell: $(OBJS)
    $(CC) $(LDIRS) -o shell $(OBJS) $(LIBS)

关于无法在 OpenBSD 上使用 editline 进行编译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36841870/

相关文章:

c - 使用硬件性能计数器是个好主意

performance - 文件系统通过大量小文件寻求性能

linux - 向 BSD 内核添加无堆栈线程?

shared-libraries - 为什么 libtool 的 "current"在 BSD 上用作 "SOVERSION"而不是 "major"?

c++ - 将 SDL_Image 与 libpng 相关联时出现问题

c - Linux 共享库的问题

核心基础,CF PRIVATE 定义在哪里

c - setsockopt() 相当于非套接字文件描述符?

c - 在我的程序中使用 OpenBSD 的 malloc、realloc 和 free

c - 整数指针数组的初始化和增量