【问题标题】:How to get missing modules in Ocaml?如何在 Ocaml 中获取缺失的模块?
【发布时间】:2017-11-19 18:57:50
【问题描述】:

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

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

我在 Ocaml 中缺少一个 Graphics 模块。在尝试将其加载到顶层(REPL 对吗?)后:

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

我收到错误消息:

Cannot find file graphics.cma.

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

ls `ocamlc -where`/graphics*` 

我读到这意味着:

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

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

然后,我尝试使用:opam install graphics 安装 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 后阅读是必要的。

之后我就可以正常运行了。

【问题讨论】:

标签: module ocaml opam


【解决方案1】:

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

因此,安装显卡(如果尚未安装)异常棘手。无需重新编译 OCaml 即可安装大多数(如果不是全部)其他模块。

不管怎样,我运行的是 macOS 10.12.4,我使用“opam switch”将我的 OCaml 系统切换到 4.03.0 版本。在生成的环境中,安装了 Graphics 模块,并且我在您提到的网站上运行示例没有问题。 (例如,我看到的是同心的红色和黄色圆圈。)

您可能会尝试执行“opam switch”以切换到最新版本的编译器,看看这是否适合您。过去我在让 Graphics 工作时遇到了麻烦,但现在它对我来说很好用。

【讨论】:

  • 感谢您的帮助。我重新安装了 x11 并安装了quartz,然后重新启动了我的机器,这似乎工作了。
猜你喜欢
  • 1970-01-01
  • 2020-03-13
  • 1970-01-01
  • 1970-01-01
  • 2019-11-04
  • 2015-12-12
  • 2018-02-12
  • 2023-04-01
  • 2011-07-02
相关资源
最近更新 更多