2016-04-25 71 views
3

我认为我必须安装editline(libedit?)库,但我可以在哪里获得OpenBSD?该代码与PC-BSD编译良好,但与OpenBSD,我得到这个错误无法在OpenBSD上使用editline进行编译

implicit declaration of rl_bind_key 

这是编辑线库没有找到。我试着在Google OpenBSD的哪里找到它,但没有找到它。你可以帮我吗?我使用的标题是

#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> 

的Makefile

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根据谷歌似乎我必须链接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 
+1

显示(可能如'make'完成)编译命令 –

+1

相关问题:http://stackoverflow.com/q/22886475/562459 –

回答

1

检查其中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) 
+0

它在'在/ usr /本地/包括/ ereadline/readline的/ readline.h' –

相关问题