[解決(在底部)。安裝石英和重新安裝與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