OCaml:运行“dune init exec”后出现沙丘构建错误

dou*_*uyu 0 ocaml dune

我是 OCaml 新手,我按照教程搭建了开发环境。然后我尝试使用沙丘和 OCaml 的helloworld示例,但遇到以下错误:

\n
$ dune init exe helloworld\nSuccess: initialized executable component named helloworld\n$ dune build\nError: I cannot find the root of the current workspace/project.\nIf you would like to create a new dune project, you can type:\n\n    dune init project NAME\n\nOtherwise, please make sure to run dune inside an existing project or\nworkspace. For more information about how dune identifies the root of the\ncurrent workspace/project, please refer to\nhttps://dune.readthedocs.io/en/stable/usage.html#finding-the-root\n
Run Code Online (Sandbox Code Playgroud)\n

目录结构:

\n
.\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 _build\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 log\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 dune\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 helloworld.ml\n
Run Code Online (Sandbox Code Playgroud)\n

沙丘:3.0.2
\nocaml:4.11.1

\n

Lho*_*ooq 7

dune-project您可以通过在项目的根目录添加一个包含以下行的文件来解决这种情况:

\n
(lang dune 3.0)\n
Run Code Online (Sandbox Code Playgroud)\n

但是,根据文档,dune init exec它不适用于创建项目:它仅为现有项目中的可执行组件创建样板(有关详细信息,dune init --help请参阅dune cli 手册)。

\n

要初始化项目,您应该运行

\n
dune init proj helloworld\n
Run Code Online (Sandbox Code Playgroud)\n

这还将生成一个模板dune-project文件以及推荐的项目文件结构。

\n
\n

注意:在沙丘 3.0 之前,dune build如果该文件不存在,则会为您创建该文件:

\n
\xe2\x9d\xaf dune init exe helloworld\nSuccess: initialized executable component named helloworld\n\xe2\x9d\xaf ls\n_build  dune  helloworld.ml\n\xe2\x9d\xaf dune build\nInfo: Creating file dune-project with this contents:\n| (lang dune 2.9)\n\xe2\x9d\xaf ls\n_build  dune  dune-project  helloworld.ml\n
Run Code Online (Sandbox Code Playgroud)\n

但是,从dune 3.0开始,dune-project在项目中找不到时不会自动添加。

\n

  • 解决了,我发现[删除自动创建和编辑沙丘项目文件的支持](https://github.com/ocaml/dune/issues/4108) (3认同)