Dune native compilation

dune
#1

Hey all, I’m trying to compile OCaml code to native executable through dune. Here is a part of my dune file:
(modes (native object))
that i thought must specify compilation type, but it’s not working.
It’s using bytecode compiler, any ideas?

0 Likes

#2

There’s nothing special to do to build a native executable. With the following dune file:

(executable
 (name x))

dune build ./x.exe should work.

How are you invoking dune? What’s not working?

0 Likes

#3

I want to use

ocamlopt

to compile OCaml code to native.
I’m using dune like this

dune --profile=release nameOfExe.exe

where release profile is defined like this

(release
(flags (:standard -O3 -w -39-33-20-50)))

0 Likes

#4

This is missing the build part. Does the following work?

dune --profile=release build nameOfExe.exe

0 Likes

#5

Sorry, yes, of course

dune build --profile=release nameOfExe.exe

Just typo

0 Likes

#6

You say that it’s not working, but can you give more details? What happens when you run this command? How do you know that it is using the bytecode compiler?

0 Likes

#7

When i run this command I’m getting error that ocamlc doesn’t have -O3 option(for every file of OCaml source code) and indeed it doesn’t, where’s ocamlopt does have.

0 Likes

#8

Ah, I see. That’s because ocamlc is still used for some cases, like compiling mli files.

To pass options only to ocamlopt, you can use ocamlopt_flags instead of flags. That should fix your problem.

1 Like

#9

hi there,

i’m not sure, but if you want to build an executable why don’t you use:

(modes (native exe))

instead of :

0 Likes