本文介绍了一个简单的OCaml项目的基本Oasis或Opam文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我是OCaml的新用户.我问了一个问题,以了解如何设置基本的OCaml项目,但我仍然有问题.跳到最后一个TL; DR I am a new OCaml user. I have asked a question to learn how to set up a basic OCaml project, but I still have issues. Jump to the end for a TL;DR例如,我正在尝试学习Irmin.在Irmin的主页上,我看到我必须做For instance, I am trying to learn Irmin. On the home page of Irmin I see I have to doopam install irmin git cohttp这样做,我最终得到的是Irmin版本0.8.3.不幸的是,我无法遵循他们的示例,因为显然Irmin的版本为0.9.4,并且API似乎已更改.因此,我想开始一个仅依赖Irmin 0.9.4的干净项目Doing so, I end up with Irmin version 0.8.3. Unfortunately, I cannot follow their examples, because apparently Irmin is at version 0.9.4, and it looks like the API has changed. So, I would like to start a clean project having as dependency just Irmin 0.9.4首先,我设置了一个opam开关First, I have set up an opam switch with opam switch install playground -A 4.02.1确保在干净的面板上工作.然后,我创建了一个基本的_oasis文件,如下所示:to be sure to work on a clean slate. Then, I have created a basic _oasis file that looks like thisOASISFormat: 0.4Name: PlaygroundVersion: 0.1.0Synopsis: OCaml playgroundAuthors: Andrea FerrettiLicense: Apache-2.0BuildTools: ocamlbuildBuildDepends: irmin, irmin.unix, lwt, lwt.unix,然后我从example.ml的Irmin主页中复制了示例.and then I have copied the example from the Irmin homepage in example.ml.open Lwtopen Irmin_unixlet store = Irmin.basic (module Irmin_git.FS) (module Irmin.Contents.String)let config = Irmin_git.config ~root:"/tmp/irmin/test" ~bare:true ()let prog = Irmin.create store config task >>= fun t -> Irmin.update (t "Updating foo/bar") ["foo"; "bar"] "hi!" >>= fun () -> Irmin.read_exn (t "Reading foo/bar") ["foo"; "bar"] >>= fun x -> Printf.printf "Read: %s\n%!" x; return_unitlet () = Lwt_main.run prog如果我先执行oasis setup,然后又执行ocamlbuild example.ml,则会遇到一堆错误If I do oasis setup and then ocamlbuild example.ml I get a bunch of errorsW: Cannot get variable ext_objW: Cannot get variable ext_libW: Cannot get variable ext_dllW: Cannot get variable ocamlfind所以简而言之,我的问题是:So in short my question is:推荐答案因此,首先,您的_oasis文件中没有任何活动目标.我的意思是,OASIS与构建可执行文件和库有关.您也没有描述.这意味着您的BuildDepends没有任何作用,因为它仅对Library和Executable条目有意义.因此,第一近似为:So, first of all your don't have any active targets in your _oasis file. What I mean, is that OASIS is about building exectuables and libraries. You haven't described either. That means, that your BuildDepends doesn't have any effect, since it has only sense for Library and Executable entries. So, a first approximation would be the following: OASISFormat: 0.4Name: PlaygroundVersion: 0.1.0Synopsis: OCaml playgroundAuthors: Andrea FerrettiLicense: Apache-2.0BuildTools: ocamlbuildBuildDepends: irmin.unix, lwt.unixExecutable "example" Path: . MainIs: example.ml CompiledObject: best如果您使用的不是最新版本,则可以尝试说服opam约束求解器,您确实需要该特定版本,例如:If you got a version that is not the newest, then you can try to persuade opam constraint solver, that you really need that specific version, like: opam install irmin.0.9.4 git cohttp此外,opam内部约束求解器不是很完善,因此请确保在系统上安装了aspcud.以下将在全新的ubuntu安装上安装带有aspcud的最新opam:Also, opam internal constraint solver isn't very sophisticated, so make sure that you have aspcud installed on your system. The following will install the latest opam with aspcud on a fresh ubuntu installation:sudo add-apt-repository --yes ppa:avsm/ppasudo apt-get updatesudo apt-get --yes install opam好吧,简单性是个人观点的问题.例如,只需使用opam文件,将build字段设置为["ocamlbuild"; "-use-ocamlfind"; "-pkgs irmin.unix,lwt.unix"; "example.native"],就可以完全没有绿洲地进行同样的操作,但是缩放的效果如何……Well, simplicity is a matter of personal opinion. For example, you can do the same without any oasis at all, just using opam file, where you set your build field, just to ["ocamlbuild"; "-use-ocamlfind"; "-pkgs irmin.unix,lwt.unix"; "example.native"], but how well it will scale... 这篇关于一个简单的OCaml项目的基本Oasis或Opam文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-17 20:58