# Incorrect build environment inside Emacs

**URL:** <https://discuss.ocaml.org/t/incorrect-build-environment-inside-emacs/1286>\
**Category:** Ecosystem\
**Tags:** spacemacs, jbuilder, emacs\
**Created:** [December 14, 2017, 3:42pm UTC](https://discuss.ocaml.org/t/incorrect-build-environment-inside-emacs/1286 "2017-12-14T15:42:37Z")\
**Posts on this page:** 4\
**Page:** 1

<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:** [December 14, 2017, 3:42pm UTC](https://discuss.ocaml.org/t/incorrect-build-environment-inside-emacs/1286/1 "2017-12-14T15:42:37Z")

</div>

I’m using Emacs (technically Spacemacs) to build an OCaml project on macOS High Sierra using OPAM and `jbuilder`, but it looks like the build command (which just calls `jbuilder build`) is picking up the wrong environment. Firstly, the OCaml compiler invoked is `/usr/local/bin/ocamlopt.opt` even though I have a local 4.04 installed via `opam switch`. Second the libraries passed to it with `-I` flag are a combination of directories from the local switch and from `/usr/local/lib`.

The actual errors I get are:

```auto
File unavailable: /usr/local/lib/ocaml/nums.cmxa

```

and

```auto
File "_none_", line 1:
Error: The file /Users/basus/.opam/4.04.1/lib/ocaml-migrate-parsetree/driver-main/migrate_parsetree_driver_main.cmxa is not a compilation unit description

```

I don’t get this error either from compiling from the shell, or from compiling under Spacemacs with the same config on Arch Linux. I don’t know how to go about fixing or debugging this.

---

<div class="post-metadata">

**Author:** ![n4323](https://avatars.discourse-cdn.com/v4/letter/n/97f17d/32.png) [@n4323](https://discuss.ocaml.org/u/n4323)\
**Post date:** [December 14, 2017, 4:52pm UTC](https://discuss.ocaml.org/t/incorrect-build-environment-inside-emacs/1286/2 "2017-12-14T16:52:21Z")

</div>

this sounds like the usual environment trouble on os x: the spacemacs app may not inherit the shell environment that opam tells you to set up?

---

<div class="post-metadata">

**Author:** ![perry](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/perry/32/518_2.png) [@perry](https://discuss.ocaml.org/u/perry)\
**Post date:** [December 14, 2017, 5:17pm UTC](https://discuss.ocaml.org/t/incorrect-build-environment-inside-emacs/1286/3 "2017-12-14T17:17:33Z")

</div>

This sounds like your .emacs doesn’t have the right paths etc. in it. You will need to edit it appropriately. However, you should explain _how_ you are invoking the build from within emacs so we can be sure…

---

<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:** [December 14, 2017, 7:35pm UTC](https://discuss.ocaml.org/t/incorrect-build-environment-inside-emacs/1286/4 "2017-12-14T19:35:43Z")

</div>

It was indeed a problem with `PATH`. I had a line `(setq shell-command-switch "-lc")` in my configuration that was causing the issues. Removing that seems to let things work properly again.
