ocamlbuild以错误的顺序链接库

时间:2018-04-25 12:12:58

标签: ocaml coq ocamlbuild

我试图在OCaml中使用来自coq的库中的_CoqProject解析器(我欢迎更好的替代方法来获取coq项目的.v文件,如果该库不适合外部使用,是吗?),但ocamlbuild似乎是以错误的顺序链接库。

考虑这个最小的示例文件

open CoqProject_file
let x = read_project_file

coq.lib包(与coq捆绑在一起)以某种方式取决于threads,而following this answer建议使用-tag thread,但我仍然得到链接threads时发现以下错误coq.lib

$ ocamlbuild -pkg coq.lib -tag thread -cflag -rectypes a.native                                                                                                             /tmp/p
+ /home/sam/.opam/4.06.0+coq-8.7/bin/ocamlopt.opt -I /home/sam/.opam/4.06.0+coq-8.7/lib/coq/config -I /home/sam/.opam/4.06.0+coq-8.7/lib/coq/lib -I /home/sam/.opam/4.06.0+coq-8.7/lib/ocaml /home/sam/.opam/4.06.0+coq-8.7/lib/ocaml/str.cmxa /home/sam/.opam/4.06.0+coq-8.7/lib/ocaml/unix.cmxa /home/sam/.opam/4.06.0+coq-8.7/lib/coq/lib/clib.cmxa -thread threads.cmxa a.cmx -o a.native
File "_none_", line 1:
Error: No implementations provided for the following modules:
         Thread referenced from /home/sam/.opam/4.06.0+coq-8.7/lib/coq/lib/clib.cmxa(Exninfo)
         Mutex referenced from /home/sam/.opam/4.06.0+coq-8.7/lib/coq/lib/clib.cmxa(Exninfo)
Command exited with code 2.

然而,如果我将ocamlopt调用分开并将-thread threads.cmxa放在clib.cmxa

之前,则会编译
$ cd _build/
$ /home/sam/.opam/4.06.0+coq-8.7/bin/ocamlopt.opt -I /home/sam/.opam/4.06.0+coq-8.7/lib/coq/config -I /home/sam/.opam/4.06.0+coq-8.7/lib/coq/lib -I /home/sam/.opam/4.06.0+coq-8.7/lib/ocaml /home/sam/.opam/4.06.0+coq-8.7/lib/ocaml/str.cmxa /home/sam/.opam/4.06.0+coq-8.7/lib/ocaml/unix.cmxa -thread threads.cmxa /home/sam/.opam/4.06.0+coq-8.7/lib/coq/lib/clib.cmxa a.cmx -o a.native

拨打ocamlbuild的正确方法是什么?

1 个答案:

答案 0 :(得分:3)

如果使用ocamlfind软件包,则应使用-use-ocamlfind标志。

为什么-tag thread需要¹没有好的解决方案¹。 OCaml Threads接口有两种不同的实现(一种是os线程,一种是绿线程),coq.lib依赖于接口,但不会决定用户使用哪一种,所以你必须手动指定它,例如使用-tag thread

¹:一种解决方案是通过弃用vmthreads(绿色线程)来删除这个选择,这在实践中很少使用。