OCaml:运行"沙丘初始化可执行文件"后的沙丘构建错误



我是OCaml的新手,我按照教程设置了一个开发环境。然后,我尝试了使用沙丘和OCaml的helloworld示例,但发现了以下错误:

$ dune init exe helloworld
Success: initialized executable component named helloworld
$ dune build
Error: I cannot find the root of the current workspace/project.
If you would like to create a new dune project, you can type:
dune init project NAME
Otherwise, please make sure to run dune inside an existing project or
workspace. For more information about how dune identifies the root of the
current workspace/project, please refer to
https://dune.readthedocs.io/en/stable/usage.html#finding-the-root

目录结构:

.
├── _build
│   └── log
├── dune
└── helloworld.ml

沙丘:3.0.2OCAML:4.11.1

您可以通过在项目的根目录下添加一个dune-project文件来解决此问题,该文件填充了以下行:

(lang dune 3.0)

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

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

dune init proj helloworld

这也将生成一个模板dune-project文件以及建议的项目文件结构。


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

❯ dune init exe helloworld
Success: initialized executable component named helloworld
❯ ls
_build  dune  helloworld.ml
❯ dune build
Info: Creating file dune-project with this contents:
| (lang dune 2.9)
❯ ls
_build  dune  dune-project  helloworld.ml

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

最新更新