簡體   English   中英

無法在Ocaml TopLevel中使用FindLib加載電池

[英]Can't load batteries using FindLib in Ocaml TopLevel

我成功安裝了ocaml-batteries-includedfindlib

我可以毫無問題地做'ocamlfind ocamlc -package batteries -c mycode.ml`。

另外,如果我做ocamlfind list ,我得到

$ ocamlfind list
batteries           (version: 2.0)
batteries.pa_comprehension (version: 2.0)
batteries.pa_comprehension.syntax (version: 2.0)
batteries.pa_llist  (version: 2.0)
batteries.pa_llist.syntax (version: 2.0)
batteries.pa_string (version: 2.0)
batteries.pa_string.syntax (version: 2.0)
batteries.syntax    (version: 2.0)
bigarray            (version: [distributed with Ocaml])
camlp4              (version: [distributed with Ocaml])
...

問題是using batteries ocaml (toplevel) using batteries

我已經設置了.ocamlinit

#use "topfind";;

Toploop.use_silently
             Format.err_formatter (Filename.concat (Findlib.package_directory
             "batteries") "battop.ml");;

但是當我啟動ocaml ,我得到了這個:

$ ocaml
        OCaml version 4.00.1

Findlib has been successfully loaded. Additional directives:
  #require "package";;      to load a package
  #list;;                   to list the available packages
  #camlp4o;;                to load camlp4 (standard syntax)
  #camlp4r;;                to load camlp4 (revised syntax)
  #predicates "p,q,...";;   to set these predicates
  Topfind.reset();;         to force that packages will be reloaded
  #thread;;                 to enable threads

Exception: Fl_package_base.No_such_package ("batteries", "").

此外,如果我在ocaml toplevel#list ,我得到

# #list;;
bigarray            (version: [distributed with Ocaml])
camlp4              (version: [distributed with Ocaml])
camlp4.exceptiontracer (version: [distributed with Ocaml])
camlp4.extend       (version: [distributed with Ocaml])
...

我看不到batteries包。


有什么問題?

你有沒有使用OPAM的原因? https://github.com/OCamlPro/opam

安裝OPAM,切換到您最喜歡的4.0x版本編譯器(例如opam switch 4.00.1 ),然后運行: opam install batteries 我建議使用opam install utop並使用utop而不是vanilla toplevel。 在任一情況下:

將以下內容放在~/.ocamlinit

#use "topfind";;
#require "batteries";;
open Batteries;;

這就是讓電池工作所需的一切。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM