2017-06-16 146 views
0

[解决(在底部)。安装石英和重新安装与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之后阅读是必要的。

之后,我可以运行良好。

+0

你检查了这个:https://stackoverflow.com/questions/40903406/not-getting-graphics-even-when-reinstalled-ocaml-mac-os-x? – Lhooq

+0

对应于我给你评论的链接,不是? ;-) – Lhooq

回答

2

图形模块是基本OCaml安装的可选部分,而不是外部模块。这就解释了为什么你不能使用OPAM进行安装。您所显示的OPAM模块仅测试在当前OCaml系统中安装的是否为。它不能(因此也不会尝试)将图形安装为单独的模块。

因此,安装图形(当它尚未安装时)是非常棘手的。不需要重新编译OCaml来安装大多数(如果不是全部的话)其他模块。

值得一提的是,我运行的是macOS 10.12.4,我使用“opam switch”将OCaml系统切换到4.03.0版本。在由此产生的环境中,图形模块已经安装好了,我没有在你提到的网站上运行这些例子的麻烦。 (例如,首先我看到同心的红色和黄色圆圈。)

您可能会尝试使用“opam switch”来切换到最新版本的编译器,并查看它是否会为您带来好处。在过去,我无法让图形工作,但它现在对我来说很好。

+0

感谢您的帮助。我重新安装了x11并安装了石英,然后重新启动了我的机器,这似乎工作。 – 1N5818