通过ocamlbuild/ocamlfind链接库

通过ocamlbuild/ocamlfind链接库,ocaml,ocamlbuild,js-of-ocaml,Ocaml,Ocamlbuild,Js Of Ocaml,我有一个名为ojasmine的本地固定OPAM项目,我希望将其编译为库,供另一个名为test_tournabox的项目使用(最终编译为javascript)。但是,test_tournabox的编译失败,出现链接错误 我编译ojasmine如下,给出目标ojasmine.cma: ocamlbuild -cflag -annot -use-ocamlfind -pkgs js_of_ocaml.log,js_of_ocaml,js_of_ocaml.syntax -syntax camlp4o

我有一个名为ojasmine的本地固定OPAM项目,我希望将其编译为库,供另一个名为test_tournabox的项目使用(最终编译为javascript)。但是,test_tournabox的编译失败,出现链接错误

我编译ojasmine如下,给出目标ojasmine.cma:

ocamlbuild -cflag -annot -use-ocamlfind -pkgs js_of_ocaml.log,js_of_ocaml,js_of_ocaml.syntax -syntax camlp4o ojasmine.cma
Finished, 5 targets (5 cached) in 00:00:00.
然后我像这样安装它:

ocamlfind install ojasmine META _build/ojasmine.cma
我发现很奇怪,ojasmine.cma不在我的项目目录中,而是在_build目录中

输出为:

Installed /home/laheadle/.opam/4.02.0/lib/ojasmine/ojasmine.cma
Installed /home/laheadle/.opam/4.02.0/lib/ojasmine/META
接下来,我将
cd
转到我的tournabox项目,并尝试构建测试套件:

ocamlbuild -cflag -annot -use-ocamlfind -pkgs js_of_ocaml.log,js_of_ocaml,js_of_ocaml.syntax,ojasmine -syntax camlp4o test_tournabox.byte
+ ocamlfind ocamlc -linkpkg -syntax camlp4o -package ojasmine -package js_of_ocaml.syntax -package js_of_ocaml -package js_of_ocaml.log choice.cmo util.cmo entry.cmo ttypes.cmo columns.cmo countries.cmo country_group.cmo jsutil.cmo performance_group.cmo round_group.cmo seed_group.cmo tlog.cmo tourney.cmo tournabox_lib.cmo test_tournabox.cmo -o test_tournabox.byte
此操作失败,错误如下:

Error: Error while linking test_tournabox.cmo:
Reference to undefined global `Ojasmine'
似乎ojasmine.cma没有链接到可执行的test_tournabox.byte。但我希望-linkpkg参数能够为这一点做出安排。我错过了什么

编辑:这是元文件:

description = "Unit Tests for javascript"
requires = "js_of_ocaml,js_of_ocaml.syntax"
version = "0.1"
以下是ocamlobjinfo:

trusty)laheadle@localhost:~/ocaml/ojasmine$ ocamlobjinfo _build/ojasmine.cma 
File _build/ojasmine.cma
Force custom: no
Extra C object files:
Extra C options:
Extra dynamically-loaded libraries:
Unit name: Ojasmine
Interfaces imported:
        ef5bf1a1d49ad28ddd8176a4f17055e1        Ojasmine
        c1a8a443b33589e4865a918c21fbbeb4        Js
        5de66fdff01f2735974be770893841e1        Pervasives
        a88f91d0f04fd66bc0bbaaf347081e95        CamlinternalFormatBasics
Uses unsafe features: no
Force link: no
ocamlfind认为:

(trusty)laheadle@localhost:~/ocaml/ojasmine$ ocamlfind query ojasmine
/home/laheadle/.opam/4.02.0/lib/ojasmine
这是:

(trusty)laheadle@localhost:~/ocaml/ojasmine$ ls `ocamlfind query ojasmine`
META  ojasmine.cma
以下是ojasmine.ml:

open Js

let describe (s : js_string t) (f: unit -> unit) : unit =
  Js.Unsafe.fun_call (Js.Unsafe.variable "describe")
    [| Js.Unsafe.inject s;
       Js.Unsafe.inject (Js.wrap_callback f) |]

let it (s : js_string t) (f: unit -> unit) : unit =
  Js.Unsafe.fun_call (Js.Unsafe.variable "it")
    [| Js.Unsafe.inject s;
       Js.Unsafe.inject (Js.wrap_callback f) |]

class type matcher = object
  method toBe: bool t -> unit meth
  method _not: matcher t readonly_prop
end

let expect_bool (b: bool t) : matcher t =
  Js.Unsafe.fun_call (Js.Unsafe.variable "expect") [|Js.Unsafe.inject b; |]
和ojasmine.mli:

open Js
val describe: js_string t -> (unit -> unit) -> unit

val it: js_string t -> (unit -> unit) -> unit

class type matcher = object
  method toBe: bool t -> unit meth
  method _not: matcher t readonly_prop
end

val expect_bool: bool t -> matcher t

您的
META
文件应该包含一个
archive
变量,以便
ocamlfind
可以正确地将您的程序链接到归档文件,而不是对象文件。您还需要安装
cmi
文件。(而且,虽然编译不需要它,但安装
mli
文件是一种很好的方式)。因此,将以下内容添加到您的
META

archive(byte) = "ojasmine.cma"

不要忘记安装
cmi

您能否提供针对
ojasmine.cma
ocamlobjinfo
的输出?该软件包是否在ocamlfind查询/列表下出现?您能用ocamlfind将CMA加载到顶级吗?查看元文件可能会有所帮助。也许它没有提供好的链接信息。我已经更新了它,除了顶层之外,所有问题的答案都在这里。我现在正在调查此事。