我正在尝试使用 ocamlfind 安装库。我正在使用 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
哦,META文件是:
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 的开头,但我得到了类似的“未绑定模块 Owebl”。我很困惑为什么这些模块都是未绑定的。我错过了什么?