# How to pass CFLAGS into a dune project?

**URL:** <https://discuss.ocaml.org/t/how-to-pass-cflags-into-a-dune-project/4470>\
**Category:** Ecosystem\
**Tags:** build, dune\
**Created:** [October 1, 2019, 3:29pm UTC](https://discuss.ocaml.org/t/how-to-pass-cflags-into-a-dune-project/4470 "2019-10-01T15:29:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![olafhering](https://avatars.discourse-cdn.com/v4/letter/o/a4c791/32.png) [@olafhering](https://discuss.ocaml.org/u/olafhering)\
**Post date:** [October 1, 2019, 3:29pm UTC](https://discuss.ocaml.org/t/how-to-pass-cflags-into-a-dune-project/4470/1 "2019-10-01T15:29:39Z")

</div>

Is there a way to pass compiler flags to an existing dune based project? The documentaton does not seem to cover this.

I’m looking for the equivalent of ‘env CFLAGS=“some string” ./configure’. Right now projects can query pkg-config to receive at least the most required CFLAGS/LDFLAGS.

The ‘dune build --verbose’ output has ‘ocamlc\_cflags’, which contains the CFLAGS used for ocaml itself. It seems there is no way to access it.

Was it ever considered to inject CFLAGS into projects?

---

<div class="post-metadata">

**Author:** ![ancolie](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/ancolie/32/6189_2.png) [@ancolie](https://discuss.ocaml.org/u/ancolie)\
**Post date:** [October 1, 2019, 6:54pm UTC](https://discuss.ocaml.org/t/how-to-pass-cflags-into-a-dune-project/4470/2 "2019-10-01T18:54:21Z")

</div>

When writing e.g. C bindings, you can do [this](https://github.com/ahrefs/ocaml-jemalloc/blob/master/src/dune#L6). If your question is about how to override this directly when invoking dune, I don’t know if it’s possible.

---

<div class="post-metadata">

**Author:** ![olafhering](https://avatars.discourse-cdn.com/v4/letter/o/a4c791/32.png) [@olafhering](https://discuss.ocaml.org/u/olafhering)\
**Post date:** [October 1, 2019, 6:57pm UTC](https://discuss.ocaml.org/t/how-to-pass-cflags-into-a-dune-project/4470/3 "2019-10-01T18:57:45Z")

</div>

It should be possible to inject CFLAGS from outside.

Meanwhile, while debugging something else, I noticed that gcc is indeed invoked with the same CFLAGS that were used to build ocaml itself. This is good enough for my use case.
