2017-06-16 206 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