【问题标题】:Ocamlbuild and Packages installed via Opam通过 Opam 安装的 Ocamlbuild 和软件包
【发布时间】:2013-05-28 02:38:14
【问题描述】:

我正在尝试制作这段代码:

open Lwt;;
open Cohttp;;
(* a simple function to access the content of the response *)
let content = function
  | Some (_, body) -> Cohttp_lwt_unix.Body.string_of_body body


(* launch both requests in parallel *)
let t = Lwt_list.map_p Cohttp_lwt_unix.Client.get
  (List.map Uri.of_string
     [ "http://example.org/";
       "http://example2.org/" ])

(* maps the result through the content function *)
let t2 = t >>= Lwt_list.map_p content

(* launch the event loop *)
let v = Lwt_main.run t2

但是,当我运行时

Ocamlbuild file.native

我收到未绑定的模块错误。

这些模块是通过 opam 安装的,当我运行时

ocamlfind query lwt 
/home/chris/.opam/system/lib/lwt
ocamlfind query cohttp
/home/chris/.opam/system/lib/cohttp

如何让 Ocamlbuild 找到这两个包?

我试过了

Ocamlbuild -pkgs cohttp,lwt file.native 

它没有工作。它谈到了一个可能不正确的扩展名。不过我不认为这是问题所在。

如果有人能给我正确的代码来执行此操作,将不胜感激。谢谢!

【问题讨论】:

  • 我过去遇到过一个问题,我将 ocamlbuild 安装在两个不同的位置,因此这两个安装在搜索库时会检查不同的目录。您可以尝试:“/home/chris/.opam/bin/ocamlbuild -use-ocamlfind -pkgs cohttp.lwt file.native”(如果路径不太正确,请更正路径)以确保您没有看到相同的行为.

标签: ocaml ocamlbuild opam


【解决方案1】:

Cohttp 已更新,因此我已更正您的代码以使用最新版本:

open Lwt;;
open Cohttp;;
(* a simple function to access the content of the response *)
let content = function
| Some (_, body) -> Cohttp_lwt_body.string_of_body body
| None -> assert false


(* launch both requests in parallel *)
let t = Lwt_list.map_p Cohttp_lwt_unix.Client.get
(List.map Uri.of_string
    [ "http://google.com";
    "http://yahoo.com" ])

(* maps the result through the content function *)
let t2 = t >>= Lwt_list.map_p content

(* launch the event loop *)
let v = Lwt_main.run t2

你可以用

ocamlbuild -use-ocamlfind -pkgs cohttp.lwt file.native

几个cmets:

1) 您应该使用 -use-ocamlfindocamlbuild 来使用 opam(或任何其他已安装的 ocaml 库)

2) 要将 cohttp 与 lwt 一起使用,您应该使用 cohttp.lwt 包。添加lwt 也不是绝对必要的。

【讨论】:

  • 这不起作用。我收到一条错误消息,说 Ocamlfind 找不到包 cohttp.lwt,当我在原始指令中使用“-use-ocamlfind”标志时,这也不起作用。不过,我确实将您的代码粘贴到了我的文件中。
  • 应该ocamlfind query cohttp.lwt返回一个路径,否则你没有正确安装cohttp。
  • Ocamlfind query cohttp.lwt 说这个包没有安装。我卸载了我的 cohttp 包,然后用 opam 重新安装了它,我仍然收到同样的错误。这可能是 OPAM 问题吗?
  • 安装 lwt 然后安装 cohttp。否则是的,我不确定问题可能是什么,请检查您运行的 cohttp 版本。 opam info cohttp
  • 我删除了这两个软件包,并按照您建议的顺序重新安装了它们,但这不起作用。如果重要的话,我在 Ubuntu 12.04 上运行 Ocaml 3.12.1。
【解决方案2】:

我通过卸载我通过发行版的包管理器安装的 ocaml-findlib 版本解决了这个问题。出于某种原因,ocamlbuild 试图使用它而不是opam 提供的版本,尽管后者在我的$PATH 上是第一个。

通过我的发行版的包管理器安装的ocamlfind 版本找不到我通过opam 安装的本地包。

根据http://brion.inria.fr/gallium/index.php/Using_ocamlfind_with_ocamlbuildocamlbuild 自 3.12 起通过-use-ocamlfind 标志包含对ocamlfind 的支持,因此您应该在这方面做得很好。您可以通过ocamlbuild --help | grep ocamlfind查看。如果您的版本支持它,那么您应该能够按照@rgrinberg 的描述构建您的包。

【讨论】:

  • 我有同样的问题,除了没有 root 访问权限,我无法删除发行版的 ocamlfind。我想知道我是否可以以某种方式“遮蔽”它?..
猜你喜欢
  • 1970-01-01
  • 2015-12-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-08-14
  • 2020-12-08
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多