# Pass custom CFLAGS while building ocaml

**URL:** <https://discuss.ocaml.org/t/pass-custom-cflags-while-building-ocaml/6004>\
**Category:** Ecosystem\
**Created:** [June 19, 2020, 3:07pm UTC](https://discuss.ocaml.org/t/pass-custom-cflags-while-building-ocaml/6004 "2020-06-19T15:07:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![vsiles](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/vsiles/32/2257_2.png) [@vsiles](https://discuss.ocaml.org/u/vsiles)\
**Post date:** [June 19, 2020, 3:07pm UTC](https://discuss.ocaml.org/t/pass-custom-cflags-while-building-ocaml/6004/1 "2020-06-19T15:07:07Z")

</div>

If I understand ocaml’s `configure` file (I’m looking at \>= 4.09.1), I can run `./configure CFLAGS=$MYFLAGS` to configure ocaml with custom CFLAGS. However I am not running the `configure` by hand, but as part of a `opam init/opam switch create` process.

My understanding is that I could patch ocaml’s opam file with my new flags, but I didn’t find in the doc how to access environment variables from a opam file.  
In the past (4.07.1) we were patching the configure file directly, but it seems things have changed since then.

Is it the right path to follow or are there other solutions ?

Best,  
V.

---

<div class="post-metadata">

**Author:** ![nojb](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/nojb/32/519_2.png) [@nojb](https://discuss.ocaml.org/u/nojb)\
**Post date:** [June 19, 2020, 3:23pm UTC](https://discuss.ocaml.org/t/pass-custom-cflags-while-building-ocaml/6004/2 "2020-06-19T15:23:27Z")

</div>

As far as I know currently `CFLAGS` and `LDFLAGS` are not properly taken into account by `./configure`. See [https://github.com/ocaml/ocaml/issues/8648](https://github.com/ocaml/ocaml/issues/8648), where you can also find information about some workarounds.

Cheers,  
Nicolás

---

<div class="post-metadata">

**Author:** ![vsiles](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/vsiles/32/2257_2.png) [@vsiles](https://discuss.ocaml.org/u/vsiles)\
**Post date:** [June 22, 2020, 7:42am UTC](https://discuss.ocaml.org/t/pass-custom-cflags-while-building-ocaml/6004/3 "2020-06-22T07:42:33Z")

</div>

Thank you for the link. I’m still struggling with it but it is very helpful 🙂
