【问题标题】:Unbound module Findlib error when I was compilering a Ocaml file which contains "open Findlib"编译包含“打开 Findlib”的 Ocaml 文件时出现未绑定模块 Findlib 错误
【发布时间】:2022-01-23 08:31:47
【问题描述】:

我写了一个Ocaml文件,它只包含一行代码:open Findlib,然后我保存文件并命名为test.ml。在Ocaml64(Ocaml for windows)环境中,我输入命令ocamlc -o test test.ml,有一个错误:Error:Unbound module Findlib。 但是如果我打开 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;;
# 

它可以工作,所以我确定Findlib库存在,我不知道为什么当我编译包含open findlib的文件时会发生错误。

【问题讨论】:

    标签: compiler-errors ocaml ocamlfind


    【解决方案1】:

    您需要将findlib 库链接到您的可执行文件。 ocamlfind 实用程序可以通过多种方式使用:

    ocamlfind ocamlc -package findlib -o test test.ml
    

    例如:

    $ cat test.ml
    open Findlib
    
    let () = print_endline "hello"
    
    $ ocamlfind ocamlc -package findlib -o test test.ml
    $ ./test
    hello
    $
    

    也可以使用ocamlfind查询库所在位置:

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

    然后告诉ocamlc 在链接您的程序时将该目录作为查找库的位置。

    $ 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
    $
    

    【讨论】:

      猜你喜欢
      • 2012-09-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-19
      • 2012-11-21
      • 2020-09-11
      • 2014-05-19
      相关资源
      最近更新 更多