首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >OCamlfind本地库解绑定模块

OCamlfind本地库解绑定模块
EN

Stack Overflow用户
提问于 2015-03-21 00:51:24
回答 2查看 953关注 0票数 1

我正在尝试使用ocamlfind来安装图书馆。我正在使用OCamlMakeFile。这是我的Makefile:

代码语言:javascript
复制
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):

代码语言:javascript
复制
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安装库:

代码语言:javascript
复制
ocamlfind install owebl META owebl.a owebl.cma owebl.cmxa

噢,元文件是:

代码语言:javascript
复制
version = "0.1"
name = "OWebl"
description = "A Web Framework for OCaml"
archive(byte) = "owebl.cma"
archive(native) = "owebl.cmxa"
requires = "unix,str"

在我试图编译上面使用库的示例之前,一切都是正常的。我跑:

代码语言:javascript
复制
ocamlbuild -use-ocamlfind -pkgs owebl main.native

我得到了:

代码语言:javascript
复制
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的开头,但我也得到了类似的“”。我非常不明白为什么这些模块都是不绑定的。我遗漏了什么?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-03-21 03:59:40

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

票数 2
EN

Stack Overflow用户

发布于 2015-03-21 01:36:34

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

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29178010

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档