Flags in Foreign Code

Depending on the use_standard_c_and_cxx_flags option, the base :standard set of flags for C will contain only ocamlc_cflags or both ocamlc_cflags and ocamlc_cppflags.

There are multiple levels where one can declare custom flags (using the Ordered Set Language), and each level inherits the flags of the previous one in its :standard set:

The %{cc} variable will contain the flags from the first three levels only.

For example, to add a flag to all C stubs in the dev profile, write:

(env
 (dev
  (c_flags (:standard -DMY_DEBUG_STUBS))))

To add flags only to one foreign_stubs field, write:

(library
 (name mylib)
 (foreign_stubs
  (language c)
  (names mystubs)
  (flags (:standard -DMYLIB_STUBS))))

If the flags come from a generated file, for example from a dune-configurator script that queried pkg-config, include them with (:include ...):

(library
 (name mylib)
 (foreign_stubs
  (language c)
  (names mystubs)
  (flags (:standard (:include c_flags.sexp))))
 (c_library_flags (:standard (:include c_library_flags.sexp))))