Dune: Set mode-only flags

Created on 21 Oct 2018  路  4Comments  路  Source: ocaml/dune

Is it possible to pass custom flags for specific modes? For example, dune file below works for dune build main.exe but fails for dune build main.exe.o because ocamlopt does not expect -lfoo. Is there a way to set -lfoo only for exe mode and not for object mode?

Problematic example:

(executable
   (name main)
   (libraries base core ctypes ctypes.foreign ctypes.stubs)
   (link_flags (-cclib -lfoo))
   (modes object exe))

Thanks!

enhancement help wanted

All 4 comments

It is not possible, but the feature makes sense. I'll tag as an enhancement in case someone would like to create a proposal for how to support this.

Thanks.

Is there any (cumbersome) hack around this limitation? I tried adding two executable stanzas but dune was not happy about two stanzas sharing same modules.

You can do what you did and simply copy the module. There's a (copy# ..) action for this purpose.

A cleaner approach depending on your situation may be to define a library with the modules that depend on -lfoo, passing -cclib -lfoo in the library_flags field. Then there should be no need to pass this flag when creating the executable.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bbc2 picture bbc2  路  7Comments

ShengChen picture ShengChen  路  5Comments

bobbypriambodo picture bobbypriambodo  路  5Comments

bobot picture bobot  路  7Comments

jvillard picture jvillard  路  8Comments