在尝试使用已安装的开发人员工具进行编译时,在macOS上找不到/正在使用editline/history.h和editline/readline.h
我正在编写关于构建您自己的LISP()的教程,出于某种原因,当我尝试编译时,我得到了以下信息:在尝试使用已安装的开发人员工具进行编译时,在macOS上找不到/正在使用editline/history.h和editline/readline.h,c,macos,readline,editline,C,Macos,Readline,Editline,我正在编写关于构建您自己的LISP()的教程,出于某种原因,当我尝试编译时,我得到了以下信息: REPL.c:4:10: fatal error: 'editline/readline.h' file not found #include <editline/history.h> ^ 1 error generated. 仅包括 #include <editline/readline.h> #包括 如果安装了命令行工具,则应该存在。此文件包含 libedit的“re
REPL.c:4:10: fatal error: 'editline/readline.h' file not found
#include <editline/history.h>
^
1 error generated.
仅包括
#include <editline/readline.h>
#包括
如果安装了命令行工具,则应该存在。此文件包含
libedit的“readline包装器”,包括历史记录函数。
OS X上不存在包含文件
我对您的代码进行了修改,并对其进行了编译和运行,没有出现任何问题。我在OSX Mavericks上,删除这行代码对我很有效:
#include <editline/history.h>
#包括
我使用的是Ubuntu 14.04
试试这个:
sudo apt get安装libeditline dev
包括:
#包括
最后编译如下:
在标志中添加-leditline
我希望这能有所帮助。使用OSX Yosemite。我删除了
#包括
然后使用cc-std=c99-Wall test.c-ledit-o test
现在一切正常了我在El Capitan,
删除#包括,
并使用cc-std=c99-Wall test.c-ledit-o test
对我有效。
在输出flad之前添加标志-ledit
,这是一个链接过程,允许编译器在程序中直接嵌入对editline的调用。或者,您将得到以下错误消息
Undefined symbols for architecture x86_64:
"_add_history", referenced from:
_main in prompt-086f90.o
"_readline", referenced from:
_main in prompt-086f90.o
ld: symbol(s) not found for architecture x86_64
FreeBSD上的以下解决方案(可能也适用于其他Unice):
如果在编译步骤中没有“-lreadline”,它将不会链接到中,并且您将得到有关未定义的对“readline”函数的引用的错误。我从构建您自己的列表开始,遇到了相同的问题。
以上所有答案对我都不起作用。经过一点研究,我发现macOs没有提供readline函数的gnu readline库,不同版本的macOs使用一个名为editline的库来模拟readline。开始
man编辑行
#包括
editline提供了一些行输入和历史的结构,
以及对其进行操作的功能。首先,您必须实例化这些结构。editline的文档不是很有用,因为它不包含任何示例。苹果公司提供了头文件,这有点帮助
我是新来的,这对我来说仍然很困惑。libedit有一些版本的源代码可以作为debian包提供。幸运的是,比我聪明的人已经深入研究了它,并使用lbedit实现了一个命令行。他的代码在这里:。
我从Build your own list中获取了Bigler先生的代码和代码,并将它们放在一起得到了这个
/* repl-macos.c
* Repl code example from builyourownlisp.com
* Modified by NB aug 2017
* Code example for editline from
* www.cs.utah.edu/~bigler/code/libedit.html
*/
#include <stdio.h>
#include <string.h>
#include <histedit.h>
char* prompt(EditLine *e){
return "lispy> ";
}
int main(int argc, char** argv){
EditLine *el; // Line editor state
History *herstory; // the rest is history
// Temp Variables
int count;
const char *usrin;
int keepreading = 1;
HistEvent ev;
// Initialize the editline state
el = el_init(argv[0], stdin, stdout, stderr);
el_set(el, EL_PROMPT, &prompt);
el_set(el, EL_EDITOR, "emacs");
// Initialize history
herstory = history_init();
if(!herstory){
fprintf(stderr, "Couldn't initialize history\n");
return 1;
}
//set history size
history(herstory, &ev, H_SETSIZE, 800);
// Set up the call back functions for history functionality
el_set(el, EL_HIST, history, herstory);
puts("Begin moLisp interpreter");
puts("Type 'exit' at prompt to exit");
while(keepreading){
usrin = el_gets(el, &count);
// add the command to the history, and echo it back to the user
if(count > 0){
history(herstory, &ev, H_ENTER, usrin);
if(strcmp(usrin, "exit\n"))
printf("No, You're a %s", usrin);
else{
puts("bye");
--keepreading;
}
}
}
// Clean up memory
// by freeing the memory pointed to within the structs that
// libedit has created.
history_end(herstory);
el_end(el);
return 0;
}
/*repl macos.c
*BuilyorWnlisp.com中的Repl代码示例
*2017年8月由NB修改
*来自的editline的代码示例
*www.cs.犹他州.edu/~bigler/code/libedit.html
*/
#包括
#包括
#包括
字符*提示符(编辑行*e){
返回“lispy>”;
}
int main(int argc,字符**argv){
EditLine*el;//行编辑器状态
历史*herstory;//剩下的就是历史
//温度变量
整数计数;
const char*usrin;
int-keepreading=1;
histev;
//初始化编辑行状态
el=el_init(argv[0],标准输入,标准输出,标准输出);
el_集合(el、el_提示和提示);
el_集(el,el_编辑器,“emacs”);
//初始化历史记录
herstory=历史_init();
如果(!herstory){
fprintf(stderr,“无法初始化历史记录\n”);
返回1;
}
//设置历史记录大小
历史(herstory和ev,H_Setize,800);
//为历史记录功能设置回调功能
el_集(el,el_HIST,history,herstory);
puts(“Begin moLisp解释器”);
puts(“在提示退出时键入“退出”);
同时(继续){
usrin=el_获取(el,&count);
//将命令添加到历史记录中,并将其回显给用户
如果(计数>0){
历史(herstory和ev、H_ENTER、usrin);
如果(strcmp(usrin,“退出”))
printf(“不,你是%s”,usrin);
否则{
卖出(“再见”);
--继续;
}
}
}
//清理内存
//通过释放指向
//libedit已经创建了。
历史(历史);;
el_端(el);
返回0;
}
注意:使用的结构的实例化发生在
while循环,以及释放那些结构正在使用的内存的函数。因此,我添加了exit命令,否则,如果退出while循环的唯一方法是中断程序,那么我认为存在内存泄漏。汇编:
cc -std=c99 -Wall REPL.c -ledit -o REPL
gcc repl macos.c-ledit-Wall-o repl edit
-需要链接编辑行
如果有任何关联,我使用的是macOs 10.4.11
这是我的编译器,输出
gcc--版本
powerpc-apple-darwin8-gcc-4.0.0(gcc)4.0.0 20041026(apple Computer,Inc.build 4061)
这本书指出的唯一问题是
c代码应该是可移植的,但事实并非如此。下一步是添加预处理器指令,以便它在linux上使用readline,在macos上使用editline。在Debian Buster 10上,我必须安装以下软件包:
sudo apt install libeditline-dev
而不是:
#include <editline/readline.h>
#include <editline/history.h>
#包括
#包括
我只包括:
#include <editline.h>
#包括
运行带有-leditline标志的程序,效果很好。只是运行了它。真的很感激!我是个笨蛋。谢谢:)架构x86_64的未定义符号:“_add_history”,引用自:_mainin prompt OYsOTI.o”_readline,引用自:_mainin prompt OYsOTI.o ld:symbol(s)not found for architecture x86_64 clang:error:linker命令失败,退出代码为1(使用-v查看调用)@Vinit:you add“libedit.dylib”链接到项目的链接库?(这就是-ledit
op
sudo apt install libeditline-dev
#include <editline/readline.h>
#include <editline/history.h>
#include <editline.h>