ocaml - OCaml / dune build 中的未绑定模块
问题描述
我第一次尝试 OCaml 并尝试一起构建几个文件。
当我运行时:
dune build bin/main.exe
我正进入(状态:
ocamlc bin/.main.eobjs/main.{cmi,cmo,cmt} (exit 2)
(cd _build/default && /usr/bin/ocamlc.opt -w @a-4-29-40-41-42-44-45-48-58-59-60-40 -strict-sequence -strict-formats -short-paths -keep-locs -g -bin-annot -I bin/.main.eobjs -I lib/.lib.objs -no-alias-deps -opaque -o bin/.main.eobjs/main.cmo -c -impl bin/main.ml)
File "bin/main.ml", line 10, characters 17-25:
Error: Unbound module Rule
这是我的 bin/main.ml 文件:
open Lib
let () =
let result = Math.add 2 3 in
print_endline (string_of_int result);
let result = Math.sub 3 1 in
print_endline (string_of_int result);
let result = Zoom.barf 3 1 in
print_endline (string_of_int result);
let result = Rule.add 3 1 in
print_endline (string_of_int result);
在 lib/inner/rule.ml 中,包含:
let add x y = x + y
let sub x y = x - y
所以我想我需要在文件中以某种方式导入 rule.mlbin/main.ml
文件?
解决方案
在 Dune 中,目前默认的是不同目录中的模块彼此不可见。这由(include_subdirs no)
节(https://dune.readthedocs.io/en/latest/dune-files.html#include-subdirs)控制。使用此设置,为了使您的模块彼此可见,您需要dune
在每个子目录中放置一个包含正确内容的文件。如果你看看 Dune 项目本身是如何做的(https://github.com/ocaml/dune),你的目录结构应该是这样的:
myproj/
bin/
dune
main.ml
lib/
dune
inner/
dune
rule.ml
各种dune
文件应包含正确的(library ...)
( https://dune.readthedocs.io/en/latest/dune-files.html#library ) 或(executable ...)
( https://dune.readthedocs.io/en/latest/dune-files。 html#executable ) 节,根据需要。
编辑:完成上述操作后,您还需要Rule
通过完整的“路径”来引用模块,即Lib.Inner.Rule
.
推荐阅读
- iframe - 服务器端检测 iframe
- excel - VBA 列出 SQL Server 分析服务器中的所有多维数据集
- svg - 使用时如何更改 SVG 中克隆元素的 ID
- reactjs - 带有 Fetch 的 React-Router 导致 404(未找到)
- powershell - youtube-dl 的 Powershell 脚本
- ios - 实例化并呈现视图控制器
- amazon-s3 - 在不定义表架构的情况下复制到雪花表中
- chocolatey - 推送一个包的多个版本(chocolatey)
- python - 保持非连续重复值熊猫的数据透视表
- python - TypeError:打印具有不正确索引的 Pandas 数据帧时不支持格式字符串