Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I produce native executables with OCamlBuild which can run in computers which don't have OCaml libraries?

I have a large OCaml project which I am compiling with ocamlbuild. Everything works fine, I have a great executable which does everything as I want. The problem is that when I take that native executable "my_prog.native" and run it somewhere else (different machine with same operating system, etc.), the new machine complaints that it can't find camomile (which is used in a Batteries library I'm using). I thought the executable we got from ocamlbuild was standalone and didn't require OCaml or Camomile to be present in the machine we ran it, but that doesn't seem to be the case.

Any ideas on how to produce really standalone executables?

like image 647
Surikator Avatar asked Nov 12 '10 19:11

Surikator


2 Answers

Most OCaml code is statically linked. There are two things which are linked dynamically:

  • C stub libraries when using bytecode (and possibly native code, although I do not think this is the case). These are dllfoo.so, corresponding to libfoo.a. If you have a libfoo.a, I think it will use that rather than dllfoo.so for native code.
  • Dynamic libraries depended on by the runtime or stub libraries (such as libc, or libgtk used by lablgtk, etc.).

Further, Camomile dynamically loads some of its Unicode data, which is a special case that does not fall into standard OCaml linking. You'll have to consult the Camomile documentation to find a way to statically embed that data.

like image 165
Michael Ekstrand Avatar answered Sep 29 '22 19:09

Michael Ekstrand


To the best of my knowledge, Camomile is dynamically loaded at runtime, so the easiest thing to do would be to provide the DLL/shared object along with your executable.

You could try forcing a static link, but this would contaminate your application with the LGPL license.

like image 39
Victor Nicollet Avatar answered Sep 29 '22 19:09

Victor Nicollet