[解决(在底部)。安装石英和重新安装与X11通过冲泡然后重新启动机器。]如何在Ocaml中获取缺少的模块?
我正在学习Ocaml,并正在通过these文档页面,并需要安装一些模块(图形)。
我错过了Ocaml中的Graphics
模块。试图加载它顶层后(REPL吧?)有:
$ ocaml
OCaml version blahblah
# #load "graphics.cma";;
# open Graphics;;
我得到的错误信息:
Cannot find file graphics.cma.
所以我漫步到this问题,没有找到与该文件后,命令:
ls `ocamlc -where`/graphics*`
我看,这意味着:
Graphics is not installed and you have to reinstall OCaml compiler enabling Graphics.
这是否意味着我每次需要新模块时都必须重新编译Ocaml?我不确定他的意思。
然后,我尝试安装Graphics:opam install graphics
。
我得到这个错误:
This package relies on external (system) dependencies that may be missing. `opam depext lablgl.1.05' may help you find the correct installation for your system.
所以我也opam depext lablgl.1.05
在此之后,我再次尝试opam install graphics
,但与此错误失败:
#=== ERROR while installing graphics.1.0 ======================================#
# opam-version 1.2.2
# os darwin
# command ocamlc -custom graphics.cma -o test
# path /Users/alexanderkleinhans/.opam/system/build/graphics.1.0
# compiler system (4.02.2)
# exit-code 2
# env-file /Users/alexanderkleinhans/.opam/system/build/graphics.1.0/graphics-24451-7afd23.env
# stdout-file /Users/alexanderkleinhans/.opam/system/build/graphics.1.0/graphics-24451-7afd23.out
# stderr-file /Users/alexanderkleinhans/.opam/system/build/graphics.1.0/graphics-24451-7afd23.err
### stderr ###
# File "_none_", line 1:
# Error: Cannot find file graphics.cma
=-=- Error report -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
The following actions failed
∗ install graphics 1.0
No changes have been performed
=-=- graphics.1.0 troubleshooting -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
=> This package checks whether the Graphics library was compiled.
此错误说Cannot find file graphics.cma
这使我回到this的问题和步骤是什么graphics.cma
(和其他模块因为我可能需要他们)。
我虽然opam
是为ocaml的的软件包管理器(此模块安装吧?)
编辑:
我做brew info ocaml
,我也安装有x11
所以我虽然这意味着我应该有它.. 。
ocaml: stable 4.04.1 (bottled), devel 4.05.0+beta3, HEAD
General purpose programming language in the ML family
https://ocaml.org/
/usr/local/Cellar/ocaml/4.04.1 (1,730 files, 194.4MB) *
Poured from bottle on 2017-06-13 at 15:23:43
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/ocaml.rb
==> Requirements
Optional: x11 ✘
==> Options
--with-flambda
Install with flambda support
--with-x11
Install with the Graphics module
--devel
Install development version 4.05.0+beta3
--HEAD
Install HEAD version
编辑2:
运行
brew install Caskroom/cask/xquartz
brew reinstall ocaml --with-x11
允许我编译,但运行给了我这个致命的异常。似乎是一个X11的东西?
Fatal error: exception Graphics.Graphic_failure("Cannot open display ")
解决
So I think the two steps that were necessary were to make sure ocaml was installed with X11. Note that `brew info ocaml` seemed to give wrong information (said it was installed with X11 but reinstall was necessary). On OSX, I also needed to install quarts.
brew install Caskroom/cask/xquartz
brew reinstall ocaml --with-x11
这个我可以编译后,却得到了执行上的错误。这是通过重新启动解决的,我在安装xquartz
之后阅读是必要的。
之后,我可以运行良好。
你检查了这个:https://stackoverflow.com/questions/40903406/not-getting-graphics-even-when-reinstalled-ocaml-mac-os-x? – Lhooq
对应于我给你评论的链接,不是? ;-) – Lhooq