How to use -thread compiler flag with ocamlbuild?
Asked Answered
R

1

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?

Renounce answered 14/5, 2013 at 21:3 Comment(1)
Who hates me so much that downvote every my question?Renounce
C
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.

Carlotacarlotta answered 14/5, 2013 at 21:30 Comment(3)
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: bitbucket.org/yminsky/core-hello-world/src/…Deckhouse
thanks. I think I haven't understood the tag things in ocamlbuildRenounce
@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.Correspond

© 2022 - 2024 — McMap. All rights reserved.