如何在ocamlbuild中使用-thread编译标志?

21

我正在使用 Jane Streetasync_core,将 package(async_core) 添加到 _tags 中。

当我使用 ocamlbuild -use-ocamlfind -I src test/test_airport.native 时,它给了我以下错误:

camlfind ocamlopt -linkpkg -package async_core -package unix -package netclient -package mongo -package xml-light src/airport.cmx test/test_airport.cmx -o test/test_airport.native ocamlfind: Error from package `threads': Missing -thread or -vmthread switch


我搜索了一下,这是我得到的链接:http://caml.inria.fr/pub/docs/manual-ocaml-4.00/manual039.html

它说:

使用系统线程的程序必须链接如下:

    ocamlc -thread other options unix.cma threads.cma other files

所以我将我的ocamlbuild命令更改为:

ocamlbuild -use-ocamlfind -cflag -thread -I src test/test_airport.native

但错误仍然存在。实际生成的ocamlbuild命令也没有-thread


我该如何处理?


谁那么讨厌我,每个问题都要踩我一下? - Jackson Tale
1个回答

23

您想知道的是是否有一个ocamlbuild标记(~ feature),可以将-thread参数添加到相关的命令行,而不是以不令人满意的方式使用-cflag进行修改。正如这篇博客文章中所解释的那样,您应该使用ocamlbuild的-documentation选项:

% ocamlbuild -documentation | grep thread
flag {. byte, link, ocaml, program, thread .} "threads.cma -thread"
flag {. link, native, ocaml, program, thread .} "threads.cmxa -thread"
flag {. doc, ocaml, thread .} "-I +threads"
flag {. compile, ocaml, thread .} "-thread"

因此答案是:在你的 ocamlbuild 调用中添加 -tag thread,或者在 _tags 中的相关位置只添加 thread


2
如果gasche的回答不够清晰,这里有一个_tags文件,是janestreet在其中一次演讲中使用的:https://bitbucket.org/yminsky/core-hello-world/src/85769e337d3e70a4b9e3246503f59991c109afe8/_tags?at=default - rgrinberg
1
谢谢。我认为我还没有理解ocamlbuild中的标签事项。 - Jackson Tale
@JacksonTale,换句话说,你需要在编译项目的目录中创建一个_tags文件。 ocamlbuild将在_tags文件中搜索标志,并使用相应的标志调用必要的命令,以处理您在_tags文件中指定的文件。 - Jason Yeo

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接