2016-04-25 22 views
3

Ich denke, dass ich die Bibliothek editline (libedit?) Installieren muss, aber wo bekomme ich es für OpenBSD? Der Code kompiliert mit PC-BSD in Ordnung, aber mit OpenBSD bekomme ich diesen FehlerKann nicht mit editline unter OpenBSD kompilieren

implicit declaration of rl_bind_key 

Es ist die editline Bibliothek, die nicht gefunden wird. Ich habe versucht zu googeln, wo es für OpenBSD zu finden ist, aber es wurde nicht gefunden. Kannst du mir helfen? Die Header ich verwende, sind

#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 

Dies ist der säumige Code

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; 
} 

Wenn ich locate editline laufen dann findet es und ich das Makefile ändern und einen neuen Fehler erhalten undefined reference to tgetnum dass nach google scheint wie muss ich mit der ncurses library verknüpfen. Jetzt kompiliert es. Die neue Makefile ist:

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

zeigen die Zusammenstellung Befehl (vielleicht durch 'make' getan) –

+1

Verwandte Frage: http://stackoverflow.com/q/22886475/562459 –

Antwort

1

prüfen, wo editline/readline.h kann (beispielsweise mit locate) gefunden werden.

Wenn es in /usr/local/include ist, sollten Sie das wahrscheinlich zu Ihrem CFLAGS in Ihrem Makefile hinzufügen;

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

Es ist in'/usr/local/include/ereadline/Readline-/readline.h' –