Hi everyone. I entered “ocaml -config” on my command and was therefore able to see (but not edit) the configure script for my compiler. (I have the 4.0.6 version of the compiler.) According to what I read, flambda is false! Oh no! So question #1 is this: How can reconfigure my OCaml configure script so that the flambda option is true? Question #2… How can I use the flambda option on the command line when using ocamlopt to compile a file. (Actually I have two .ml files. Most of the functions and assignments are in the first file, and the second file uses those functions and assignments.)
I really appreciate your help. Thank you!
P.S. I’m using Linux Ubuntu 15.04 and also last year’s version of Mac OS-X. In both cases I’ve got the same compiler. It’s the compiler for OCaml, version 4.0.6, which I believe is the most current (or almost the most current) version of the language.
Oh sorry… not “ocaml -config”. I mean ocamlopt -config. I hope that other line did not confuse anyone. Okay, thanks again!
The easiest way is to use OPAM and issue the command
opam switch 4.06.1+flambda
The other way is to recompile and reinstall OCaml from sources. Just configure with
The one thing that is not currently possible is to select between flambda and no-flambda via an ocamlopt compilation flag. Flambda needs to be “baked in” the ocamlopt compiler you’re using.
Thanks Dr. Leroy! Much appreciated! I chose the first option because it just seemed a lot easier. Do I have to do anything special to take advantage of flambda? I mean… let’s say I have two files, X.ml and Y.ml. Y.ml calls some functions from X.ml. So then I could just do this, right?
**ocamlopt -o my_executable X.ml Y.ml **
and that’s all! Or do I have to specify some option in order to take advantage of the flambda aspect of the compiler?
Once you have installed the flambda variant of the compiler, you will need to ensure that you have that variant of the compiler in your path, specifically:
eval `opam config env`
# Note: You _may_ find it useful to include this in ~/.bashrc or ~/.bash_profile
To be absolutely sure that you are using flambda, check
which ocamlopt, in which case, it should be something along the lines of
After you have all that out of the way, you can compile your ocaml code as usual. (ie: as you described
ocamlopt -o my_executable X.ml Y.ml). To make use of aggressive optimisations (at the cost of increased code size), you will want to compile with
-O3, as denoted in the help option of the compiler.
Thanks Fu. You mentioned compiling with the -03 option. What’s the syntax for that? Do I have to specifically call “flambda” as an option like ocamlopt -o my_executable flambda -03 X.ml Y.ml… or is the syntax for compilation a little different? Thanks!
I think you might be slightly confusing what opam switch does. It might be worth looking at the docs. Long story short, using flambda means using a different compiler / executable altogether, one with flambda activated. It is not a switch in a single compiler to turn flambda on and off, but rather two separate compilers, one with flambda, and one without. opam switch is really just a tool that helps you point your PATH variable to the right locations.
To answer your other question, it is
ocamlopt -O3 -o my_executable a.ml b.ml