简体   繁体   English

无法在Ocaml TopLevel中使用FindLib加载电池

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

I successfully installed ocaml-batteries-included and findlib . 我成功安装了ocaml-batteries-includedfindlib

I can do 'ocamlfind ocamlc -package batteries -c mycode.ml` without problems. 我可以毫无问题地做'ocamlfind ocamlc -package batteries -c mycode.ml`。

Also, if I do ocamlfind list , I get 另外,如果我做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])
...

The problem is using batteries in ocaml (toplevel) . 问题是using batteries ocaml (toplevel) using batteries

I have set up .ocamlinit as told: 我已经设置了.ocamlinit

#use "topfind";;

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

but when I launch ocaml , I get this: 但是当我启动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", "").

Further, if I do #list in ocaml toplevel , I get 此外,如果我在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])
...

I can't see batteries package. 我看不到batteries包。


What's the problem? 有什么问题?

Is there a reason why you're not using OPAM? 你有没有使用OPAM的原因? ( https://github.com/OCamlPro/opam ) https://github.com/OCamlPro/opam

Install OPAM, switch to your favorite version of the 4.0x compiler (for example opam switch 4.00.1 ), and run: opam install batteries . 安装OPAM,切换到您最喜欢的4.0x版本编译器(例如opam switch 4.00.1 ),然后运行: opam install batteries I recommend doing opam install utop and using utop instead of the vanilla toplevel. 我建议使用opam install utop并使用utop而不是vanilla toplevel。 In either case: 在任一情况下:

Put the following in your ~/.ocamlinit 将以下内容放在~/.ocamlinit

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

This is all you need to get batteries working. 这就是让电池工作所需的一切。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM