3
我正在做一個免費課程的練習。下面的ocaml代碼在我「製作」時編譯,但是一旦我嘗試將它放入頂層就會抱怨。爲什麼?Ocaml代碼編譯,但不與頂層
let main() =
(* Parsing arguments *)
let f_name = ref "" in
Arg.parse [ ] (fun s -> f_name := s) "Mini-Java analyzer";
(* Parsing of the source file *)
let simple_java_prog =
if String.compare !f_name "" = 0 then failwith "no program file given";
Localizing.current_file_name := !f_name;
let f_desc = open_in !f_name in
let lexbuf = Lexing.from_channel f_desc in
let java_prog =
try Java_parser.program Java_lexer.token lexbuf
with
| e ->
Printf.printf "Exception during parsing: %s\n"
(Printexc.to_string e);
failwith "Stopped" in
Simple_java_translate.tr_java_prog java_prog in
Printf.printf "finished...\n"
let _ = main()
但是,當我 「CC CE」(從Emacs的)這個代碼頂層,它給我的錯誤
....
let main() =
Error: Reference to undefined global `Localizing'
那麼,此錯誤信息,我得到了一個解釋從
http://caml.inria.fr/pub/docs/manual-ocaml/manual023.html
它說,
引用未定義的全局模塊 您忽略了使用#load將 模塊的實現加載到內存中。
因此,我試圖這樣做:#load「localizing.cmo」。但是,現在的問題是:沒有localizing.cmo 這裏是搜索結果。
bash-3.2$ ls localizing*
localizing.cmi localizing.cmx localizing.ml localizing.mli localizing.o
我想把makefile放在這裏,問題的來源不應該來自「Makefile」,除了它太大了。此外,我不應該修改makefile,因爲這是由課程網站提供的。
有什麼問題?謝謝。我有權得出結論:不是所有的ocaml程序都應該能夠在頂層執行嗎?
您可以加載'cmo'或'cma'。兩者都可以由'ocamlc [.opt]'創建。 – nlucaroni
我發現大多數問題的根源都來自'Makefile' - 大部分是酒精中毒。 – nlucaroni