我认为必须安装editline(libedit?)库,但是在哪里可以获取OpenBSD?使用PC-BSD可以很好地编译代码,但是使用OpenBSD可以得到此错误
implicit declaration of rl_bind_key
找不到的是editline库。我尝试使用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>
生成文件
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
,则可能应将其添加到CFLAGS
Makefile中;否则,请执行以下操作。
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)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句