2017-02-23 66 views
0

我在Windows上使用cygwin 64終端並且想編譯這個ocaml圖形代碼。 它保存爲.ml類型:如何編譯ocaml圖形窗口cygwin

let etat x y c=draw_circle x y 10 ;let a=(x-5) and b=(y-5) in moveto a b ;let s=string_of_int c in draw_string s;; 
etat 100 100 1;; 
etat 200 200 3;; 

我之間困惑:負載graphics.cma打開圖形Graphics.open_graph

而且,我也要用ocamlc -og graphics.cma g.ml 到編譯?

+0

使用ocamlbuild來構建您的項目:ocamlbuild -use-ocamlfind -pkg graphics .native。它將解決依賴關係。它將鏈接到graphics.cma;在你的代碼中,你需要通過打開這個模塊來引用那個模塊的功能,或者通過在Graphics前面加上前綴來明確地給出命名空間。 –

回答

0

我正在confued之間:負載graphics.cma打開圖形Graphics.open_graph

  • load是交互式頂層的指令。它不是OCaml語言的一部分。您正在使用指令來命令交互式頂層。它用於將代碼加載到頂層。

  • open Graphics是一種語言結構,它將模塊Graph中的定義名稱帶到當前範圍。這允許你寫open_graph而不是Graphics.open_graph。最好不要打開太多的模塊(如果有的話),因爲它可能會污染你的命名空間,並使你的代碼變得不那麼容易理解。

  • Graphics.open_graph是一個函數,它在被調用時會在你的機器上打開一個圖形窗口。

和我應該使用ocamlc -o克graphics.cma g.ml進行編譯。

是的,你可以使用ocamlc編譯你的代碼。 OCaml編譯器工具鏈相當難以使​​用。然而,有一個彙編管理器,稱爲ocamlbuild,那應該像魔術,例如,

ocamlbuild -pkg graphics g.byte 

你會得到一個g.byte的可執行文件,就可以運行。