21

I am using Jane Street's async_core by adding package(async_core) in _tags.

When I use ocamlbuild -use-ocamlfind -I src test/test_airport.native, it gives me the following error:

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


I googled it and here is what I got http://caml.inria.fr/pub/docs/manual-ocaml-4.00/manual039.html

It says:

Programs that use system threads must be linked as follows:

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

So I changed my ocamlbuild command like this:

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

But the error remains the same. also the actual command that ocamlbuild generated remains the same without -thread.


How can I deal with this?

Jackson Tale
  • 25,428
  • 34
  • 149
  • 271

1 Answers1

23

What you want to know is whether there is an ocamlbuild tag (~ feature) to add the -thread argument to the relevant command-lines, instead of hacking it with -cflag in unsatisfying ways. As explained in this blog post, you should use the -documentation option of ocamlbuild:

% 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"

So the answer is: add -tag thread to your ocamlbuild invocation line, or just thread in the relevant place in _tags.

gasche
  • 31,259
  • 3
  • 78
  • 100
  • 2
    In the very unlikely case that gasche's answer was not clear enough here is a _tags file janestreet used in one of their talks: https://bitbucket.org/yminsky/core-hello-world/src/85769e337d3e70a4b9e3246503f59991c109afe8/_tags?at=default – rgrinberg May 14 '13 at 21:33
  • 1
    thanks. I think I haven't understood the tag things in ocamlbuild – Jackson Tale May 14 '13 at 21:39
  • @JacksonTale, in another words, you have to create a `_tags` file in the directory where you are compiling your project. `ocamlbuild` will search for flags in the `_tags` file and invoke the necessary command with the corresponding flags for the files that you've specified in the `_tags` file. – Jason Yeo Aug 21 '13 at 06:37