问题描述
|
我正在用Ocaml编写编译器。在终端中使用
make
进行编译和测试时,tracback效果很好,例如:
export OCAMLRUNParaM=b
./Simpler-Basic test.sib
Fatal error: exception Match_failure(\"interp.ml\",45,21)
Called from file \"interp.ml\",line 97,characters 72-86
Called from file \"list.ml\",line 74,characters 24-34
Called from file \"interp.ml\",line 108,characters 9-35
Called from file \"main.ml\",line 54,characters 4-17
make: *** [all] Error 2
但是,当我在Emacs中使用Meta-x compile
和by0ѭ对其进行编译和测试时,它不会在缓冲区中显示回溯部分:
make
export OCAMLRUNParaM=b
./Simpler-Basic test.sib
Fatal error: exception Match_failure(\"interp.ml\",21)
make: *** [all] Error 2
Compilation exited abnormally with code 2 at Sat Jun 18 19:03:04
我的ѭ5中有一部分内容是我从朋友那里复制来进行追溯的:http://paste.ubuntu.com/628838/
谁能告诉我如何修改我的.emacs
,以使其在终端中显示回溯?非常感谢你
解决方法
你在哪里写
export OCAMLRUNPARAM=b
?
如果您在makefile中编写了此代码(↹代表制表符):
↹export OCAMLRUNPARAM=b
↹./Simpler-Basic test.sib
则它不起作用,因为每个makefile命令都在单独的shell中执行,因此第一行完成后环境变量分配消失了。您可以将这两行合并为一条逻辑行:
↹export OCAMLRUNPARAM=b; \\
↹./Simpler-Basic test.sib
如果在Emacs中运行Ocaml程序时总是想回溯,请在.emacs
中设置环境变量:
(setenv \"OCAMLRUNPARAM\" \"b\")
为了使Emacs可以将回溯消息识别为带有位置的错误消息,您需要在compilation-regexp-alist
中进行注册。在您的.emacs
中放入以下内容(未经测试):
(eval-after-load \"caml\"
(add-to-list \'compilation-regexp-alist
\'(\"\\\\(^Raised at\\\\|Called from\\\\) file \\\"\\\\([^\"\\n]+\\\\)\\\",line \\\\([0-9]+\\\\)\"
2 3)))