简体   繁体   English

编译包含“打开 Findlib”的 Ocaml 文件时出现未绑定模块 Findlib 错误

[英]Unbound module Findlib error when I was compilering a Ocaml file which contains "open Findlib"

I wrote a Ocaml file which only contains one line code: open Findlib ,and then I save the file and named it for test.ml .In the Ocaml64(Ocaml for windows) environment,I typed command ocamlc -o test test.ml ,there is an error: Error:Unbound module Findlib .我写了一个 Ocaml 文件,它只包含一行代码: open Findlib ,然后我保存文件并将其命名为test.ml 。在 Ocaml64(Ocaml for windows)环境中,我输入命令ocamlc -o test test.ml ,出现错误: Error:Unbound module Findlib But if I open the ocaml interactive enviroment and do it like this:但是如果我打开 ocaml 交互环境并这样做:

$ ocaml
        OCaml version 4.12.0
# #use "topfind"
  ;;
- : unit = ()
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
# open Findlib;;
# 

it works,so I'am sure the Findlib library exists,I don't know why the error will happen when I compiling the file contains open findlib .它可以工作,所以我确定 Findlib 库存在,我不知道为什么当我编译包含open findlib的文件时会发生错误。

You need to link the findlib library to your executable.您需要将findlib库链接到您的可执行文件。 The ocamlfind utility can be used in a couple of ways to do this: ocamlfind实用程序可以通过多种方式使用:

ocamlfind ocamlc -package findlib -o test test.ml

For example:例如:

$ cat test.ml
open Findlib

let () = print_endline "hello"

$ ocamlfind ocamlc -package findlib -o test test.ml
$ ./test
hello
$

Or you can use ocamlfind to query where the library is located:或者你可以使用ocamlfind来查询库所在的位置:

$ ocamlfind query findlib
/home/user/.opam/system/lib/findlib

And then include that directory as a location to find libraries.然后将该目录作为查找库的位置包含在内。

$ ocamlc -I /home/user/.opam/system/lib/findlib -o test test.ml
$ ./test
hello
$ ocamlc -I `ocamlfind query findlib` -o test test.ml
$ ./test
hello
$

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

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