# "Error: Files \<same file twice\> both define a module named Thread"

**URL:** <https://discuss.ocaml.org/t/error-files-same-file-twice-both-define-a-module-named-thread/767>\
**Category:** Ecosystem\
**Tags:** oasis, core\
**Created:** [August 25, 2017, 4:23am UTC](https://discuss.ocaml.org/t/error-files-same-file-twice-both-define-a-module-named-thread/767 "2017-08-25T04:23:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mars0i](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/mars0i/32/1058_2.png) [@mars0i](https://discuss.ocaml.org/u/mars0i)\
**Post date:** [August 25, 2017, 4:23am UTC](https://discuss.ocaml.org/t/error-files-same-file-twice-both-define-a-module-named-thread/767/1 "2017-08-25T04:23:19Z")

</div>

Using oasis, I add `<**/*>: thread` to the end of my \_tags file, because otherwise I get this error:

`ocamlfind: Error from package`threads’: Missing -thread or -vmthread switch`

I know that I need threads because I use `Core.Command` and `Core.Command.Spec` in one file, but I don’t know anything about the `threads` package, why it’s used by `Command`, etc. (That hasn’t been important to me so far; it hasn’t seemed necessary to learn more.)

I just installed a new OCaml 4.05.0 switch, and now I’m getting this mysterious error:

```
ocaml setup.ml -build
Finished, 0 targets (0 cached) in 00:00:00.
+ /Users/marshall/.opam/4.05.0/bin/ocamlfind ocamlopt -g -thread threads.cmxa -linkpkg -package batteries -package core -package owl -I src src/probutils.cmxa src/wrightfisherPDFs.cmx -o src/wrightfisherPDFs.native
File "_none_", line 1:
Error: Files /Users/marshall/.opam/4.05.0/lib/ocaml/threads/threads.cmxa
       and /Users/marshall/.opam/4.05.0/lib/ocaml/threads/threads.cmxa
       both define a module named Thread

```

Any suggestions about how to fix this or what I should look for in order to figure out what’s going on? (Or: What other information should I report here?)

I noticed that [myocamlbuild.ml](http://myocamlbuild.ml) contains this block, which seems relevant, but I don’t understand it:

```
(* The default "thread" tag is not compatible with ocamlfind.
 * Indeed, the default rules add the "threads.cma" or "threads.cmxa"
 * options when using this tag. When using the "-linkpkg" option with
 * ocamlfind, this module will then be added twice on the command line.
 *
 * To solve this, one approach is to add the "-thread" option when using
 * the "threads" package using the previous plugin.
*)
flag ["ocaml"; "pkg_threads"; "compile"] (S[A "-thread"]);
flag ["ocaml"; "pkg_threads"; "doc"] (S[A "-I"; A "+threads"]);
flag ["ocaml"; "pkg_threads"; "link"] (S[A "-thread"]);
flag ["ocaml"; "pkg_threads"; "infer_interface"] (S[A "-thread"]);
flag ["c"; "pkg_threads"; "compile"] (S[A "-thread"]);
flag ["ocaml"; "package(threads)"; "compile"] (S[A "-thread"]);
flag ["ocaml"; "package(threads)"; "doc"] (S[A "-I"; A "+threads"]);
flag ["ocaml"; "package(threads)"; "link"] (S[A "-thread"]);
flag ["ocaml"; "package(threads)"; "infer_interface"] (S[A "-thread"]);
flag ["c"; "package(threads)"; "compile"] (S[A "-thread"]);
```

---

<div class="post-metadata">

**Author:** ![mars0i](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/mars0i/32/1058_2.png) [@mars0i](https://discuss.ocaml.org/u/mars0i)\
**Post date:** [August 25, 2017, 6:16pm UTC](https://discuss.ocaml.org/t/error-files-same-file-twice-both-define-a-module-named-thread/767/2 "2017-08-25T18:16:32Z")

</div>

I have been finding similar errors on the web, although I have not yet noticed a solution for my particular problem. (Sorry, should have looked first.) For example [this one](https://github.com/ocaml/ocamlbuild/issues/66). Still looking.

However, I found that by deleting `threads.cmxa` after `-thread` in the `ocamlfind` command line above, and running that line by hand, I can build the program (wrightfisherPDFs.native). However, I’m not sure how to make oasis, etc. figure this out for me. I have looked at what’s in [setup.ml](http://setup.ml) and [myocamlbuild.ml](http://myocamlbuild.ml). Most of the incantations in those files are beyond my understanding at this point. Still working on the problem.

---

<div class="post-metadata">

**Author:** ![basus](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/basus/32/29_2.png) [@basus](https://discuss.ocaml.org/u/basus)\
**Post date:** [August 25, 2017, 6:57pm UTC](https://discuss.ocaml.org/t/error-files-same-file-twice-both-define-a-module-named-thread/767/3 "2017-08-25T18:57:36Z")

</div>

I remember occasionally running into errors of that sort while using `oasis`, unfortunately I don’t remember at the moment how to go ahead fixing. Unless you really need to be using `oasis` for some reason, I would highly recommend using `jbuilder` as your build system. It’s much faster and the interface is more streamlined (though the S-expression syntax take some getting used to). It avoids the mass of `_tags`, `ocamlfind` and `ocamlbuild` and directly invokes the OCaml compiler (I think), so you’re less likely to run into these sorts of issues.

---

<div class="post-metadata">

**Author:** ![mars0i](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/mars0i/32/1058_2.png) [@mars0i](https://discuss.ocaml.org/u/mars0i)\
**Post date:** [August 25, 2017, 7:15pm UTC](https://discuss.ocaml.org/t/error-files-same-file-twice-both-define-a-module-named-thread/767/4 "2017-08-25T19:15:50Z")

</div>

Thanks @basis. I’m willing to switch if there’s a good reason. So maybe this is it. I’m not afraid of parentheses. I started with oasis because that’s what was suggested on [ocaml.org](http://ocaml.org), and it worked. And now I’m just lazy. 🙂
