我是 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\nRun 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\nRun Code Online (Sandbox Code Playgroud)\n沙丘:3.0.2
\nocaml:4.11.1
dune-project您可以通过在项目的根目录添加一个包含以下行的文件来解决这种情况:
(lang dune 3.0)\nRun Code Online (Sandbox Code Playgroud)\n但是,根据文档,dune init exec它不适用于创建项目:它仅为现有项目中的可执行组件创建样板(有关详细信息,dune init --help请参阅dune cli 手册)。
要初始化项目,您应该运行
\ndune init proj helloworld\nRun Code Online (Sandbox Code Playgroud)\n这还将生成一个模板dune-project文件以及推荐的项目文件结构。
注意:在沙丘 3.0 之前,dune build如果该文件不存在,则会为您创建该文件:
\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\nRun Code Online (Sandbox Code Playgroud)\n但是,从dune 3.0开始,dune-project在项目中找不到时不会自动添加。