1

我正在尝试使用 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”。我很困惑为什么这些模块都是未绑定的。我错过了什么?

4

2 回答 2

2

LIB_PACK_NAME如果要将模块打包在伞形命名空间下,则应使用变量,例如OWebl,否则它们将按原样可用,例如ResponseRule等。此外,您应该指定mli文件以及变量中的ml文件。SOURCES最后,您不应该忘记安装cmi文件以及.a文件。安装mli文件也被认为是一个很好的传统,尽管不是严格要求。此外,请考虑使用OCamlMakefile安装工具而不是自定义安装脚本。

于 2015-03-21T03:59:40.070 回答
0

我不再使用 OCamlMakefile 因此不确定,但假设 OCamlMakefile 使用-for-pack OWebl选项编译内容并正确构建打包模块owebl.cmo,您还需要安装owebl.cmi.

OCaml 编译器查找cmi文件以检查模块的存在并获取它们的类型信息。如果未安装,编译器将找不到它。cmacmxa文件是对象的集合,不提供类型信息。

于 2015-03-21T01:36:34.013 回答