如何在Ocaml中找到丢失的模块?

时间:2017-06-16 22:18:04

标签: module ocaml opam

[解决了(在底部)。安装石英并通过brew重新安装x11然后重新启动机器。]

我正在学习Ocaml并且正在浏览these个文档页面,需要安装一些模块(图形)。

我错过了Ocaml中的Gr.edges()模块。尝试将其加载到顶层(REPL对吗?)后:

Graphics

我收到错误消息:

$ ocaml
       OCaml version blahblah
# #load "graphics.cma";;
# open Graphics;;

所以我徘徊到this问题并且在没有找到带有命令的文件之后:

Cannot find file graphics.cma.

我读到这意味着:

  

未安装图形,您必须重新安装OCaml编译器   启用图形。

这是否意味着我每次需要新模块时都必须重新编译Ocaml?我不确定他的意思。

然后,我尝试使用ls `ocamlc -where`/graphics*` 安装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. ,这会让我回到this问题以及获取Cannot find file graphics.cma(以及我可能需要的其他模块)的步骤。

我虽然graphics.cma是ocaml的包管理器(这个安装模块对吗?)

编辑:

我做了opam我安装了brew info ocaml,所以我觉得我应该拥有它......

x11

编辑2:

正在运行

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

允许我编译,但是跑步给了我这个致命的例外。似乎是X11的事情?

brew install Caskroom/cask/xquartz
brew reinstall ocaml --with-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 后必须阅读。

之后我可以正常运行。

1 个答案:

答案 0 :(得分:3)

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

出于这个原因,安装图形(当它尚未安装时)非常棘手。没有必要重新编译OCaml来安装大多数(如果不是全部)其他模块。

对于它的价值,我正在运行macOS 10.12.4,并且我使用“opam switch”将我的OCaml系统切换到4.03.0版本。在生成的环境中,安装了Graphics模块,在您提到的网站上运行示例时我没有遇到任何问题。 (例如,对于第一个,我看到同心的红色和黄色圆圈。)

您可以尝试使用“opam switch”切换到最新版本的编译器,看看这是否适合您。在过去,我无法让图形工作,但它现在对我很有用。

相关问题