OCamlfind 本地库未绑定模块
OCamlfind local library unbound module
我正在尝试使用 ocamlfind 安装 library。我正在使用 OCamlMakeFile。这是我的 Makefile:
OCAMLMAKEFILE = OCamlMakeFile
RESULT = owebl
SOURCES = src/utils.ml src/verb.ml src/request.ml src/template.ml src/response.ml src/rule.ml src/handler.ml src/server.ml
PACKS = unix str
all: native-code-library byte-code-library
install: libinstall
uninstall: libuninstall
include $(OCAMLMAKEFILE)
基本上,该库是我要分发的模块的集合。该库的基本用法是 (main.ml):
open Response
open Rule
open Verb
open Server
let handler =
Handler.create
(StaticRouteRule.create "/" [GET])
(FileResponse.create
~static_file:(FileResponse.StaticFile "/index.html")
())
let server = Server.create "0.0.0.0" 8080 [handler];;
server#serve
我只是运行宁"make"编译库。它生成三个文件:"owebl.a, owebl.cma, owebl.cmxa"。然后我使用 ocamlfind 安装库:
ocamlfind install owebl META owebl.a owebl.cma owebl.cmxa
哦,元文件是:
version = "0.1"
name = "OWebl"
description = "A Web Framework for OCaml"
archive(byte) = "owebl.cma"
archive(native) = "owebl.cmxa"
requires = "unix,str"
一切正常,直到我尝试编译上面使用该库的示例。我运行:
ocamlbuild -use-ocamlfind -pkgs owebl main.native
我得到:
ocamlbuild -use-ocamlfind -pkgs owebl main.native
+ ocamlfind ocamlc -c -package owebl -o main.cmo main.ml
File "main.ml", line 1, characters 5-10:
Error: Unbound module Owebl
Command exited with code 2.
Hint: Recursive traversal of subdirectories was not enabled for this build,
as the working directory does not look like an ocamlbuild project (no
'_tags' or 'myocamlbuild.ml' file). If you have modules in subdirectories,
you should add the option "-r" or create an empty '_tags' file.
To enable recursive traversal for some subdirectories only, you can use the
following '_tags' file:
true: -traverse
<dir1> or <dir2>: traverse
Compilation unsuccessful after building 2 targets (1 cached) in 00:00:00.
make: *** [fileserver] Error 10
我尝试将 open Owebl
添加到 main.ml 的开头,但我只是得到了类似的 "unbound module Owebl"。我很不明白为什么这些模块都是未绑定的。我错过了什么?
我不再使用 OCamlMakefile 因此不确定,但假设 OCamlMakefile 使用 -for-pack OWebl
选项编译东西并正确构建打包模块 owebl.cmo
,您还需要安装 owebl.cmi
.
OCaml 编译器寻找 cmi
文件来检查模块的存在并获取它们的类型信息。如果没有安装,编译器找不到它。 cma
和 cmxa
文件是对象的集合,不提供类型信息。
如果你想将你的模块打包在伞形命名空间下,你应该使用 LIB_PACK_NAME
变量,比如 OWebl
,否则它们将按原样可用,例如Response
、Rule
等。另外,您应该在 SOURCES
变量中指定 mli
文件以及 ml
文件。最后,您不应忘记安装 cmi
文件以及 .a
文件。安装 mli
文件也被认为是一个好传统,尽管不是严格要求的。此外,请考虑使用 OCamlMakefile
安装工具而不是自定义安装脚本。
我正在尝试使用 ocamlfind 安装 library。我正在使用 OCamlMakeFile。这是我的 Makefile:
OCAMLMAKEFILE = OCamlMakeFile
RESULT = owebl
SOURCES = src/utils.ml src/verb.ml src/request.ml src/template.ml src/response.ml src/rule.ml src/handler.ml src/server.ml
PACKS = unix str
all: native-code-library byte-code-library
install: libinstall
uninstall: libuninstall
include $(OCAMLMAKEFILE)
基本上,该库是我要分发的模块的集合。该库的基本用法是 (main.ml):
open Response
open Rule
open Verb
open Server
let handler =
Handler.create
(StaticRouteRule.create "/" [GET])
(FileResponse.create
~static_file:(FileResponse.StaticFile "/index.html")
())
let server = Server.create "0.0.0.0" 8080 [handler];;
server#serve
我只是运行宁"make"编译库。它生成三个文件:"owebl.a, owebl.cma, owebl.cmxa"。然后我使用 ocamlfind 安装库:
ocamlfind install owebl META owebl.a owebl.cma owebl.cmxa
哦,元文件是:
version = "0.1"
name = "OWebl"
description = "A Web Framework for OCaml"
archive(byte) = "owebl.cma"
archive(native) = "owebl.cmxa"
requires = "unix,str"
一切正常,直到我尝试编译上面使用该库的示例。我运行:
ocamlbuild -use-ocamlfind -pkgs owebl main.native
我得到:
ocamlbuild -use-ocamlfind -pkgs owebl main.native
+ ocamlfind ocamlc -c -package owebl -o main.cmo main.ml
File "main.ml", line 1, characters 5-10:
Error: Unbound module Owebl
Command exited with code 2.
Hint: Recursive traversal of subdirectories was not enabled for this build,
as the working directory does not look like an ocamlbuild project (no
'_tags' or 'myocamlbuild.ml' file). If you have modules in subdirectories,
you should add the option "-r" or create an empty '_tags' file.
To enable recursive traversal for some subdirectories only, you can use the
following '_tags' file:
true: -traverse
<dir1> or <dir2>: traverse
Compilation unsuccessful after building 2 targets (1 cached) in 00:00:00.
make: *** [fileserver] Error 10
我尝试将 open Owebl
添加到 main.ml 的开头,但我只是得到了类似的 "unbound module Owebl"。我很不明白为什么这些模块都是未绑定的。我错过了什么?
我不再使用 OCamlMakefile 因此不确定,但假设 OCamlMakefile 使用 -for-pack OWebl
选项编译东西并正确构建打包模块 owebl.cmo
,您还需要安装 owebl.cmi
.
OCaml 编译器寻找 cmi
文件来检查模块的存在并获取它们的类型信息。如果没有安装,编译器找不到它。 cma
和 cmxa
文件是对象的集合,不提供类型信息。
如果你想将你的模块打包在伞形命名空间下,你应该使用 LIB_PACK_NAME
变量,比如 OWebl
,否则它们将按原样可用,例如Response
、Rule
等。另外,您应该在 SOURCES
变量中指定 mli
文件以及 ml
文件。最后,您不应忘记安装 cmi
文件以及 .a
文件。安装 mli
文件也被认为是一个好传统,尽管不是严格要求的。此外,请考虑使用 OCamlMakefile
安装工具而不是自定义安装脚本。