Can I create my own executable files with OCamlBuild that can run on computers that do not have OCaml libraries?

I have a large OCaml project that I am compiling with ocamlbuild. Everything works just fine, I have a great executable that does everything I want. The problem is that when I take this own executable file "my_prog.native" and run it somewhere else (another machine with the same operating system, etc.), the new machine complains that it cannot find a daisy (which is used in batteries the library that I use). I thought that the executable we received from ocamlbuild was standalone and did not require OCaml or Camomile to be present in the machine where we ran it, but this does not seem to be the case.

Any ideas on how to create truly standalone executables?

+6
ocaml ocamlbuild
source share
2 answers

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

  • C stub libraries when using bytecode (and possibly native code, although I don't think so). This is dllfoo.so , the corresponding libfoo.a . If you have libfoo.a , I think he will use this instead of dllfoo.so for his own code.
  • Dynamic libraries depend on runtime or stub libraries (for example, libc or libgtk , used by lablgtk , etc.).

In addition, Camomile dynamically loads some of its Unicode data, which is a special case that is not part of the standard OCaml layout. You will need to consult the Camomile documentation to find a way to statically embed this data.

+7
source share

As far as I know, Camomile is dynamically loaded at runtime, so the easiest way is to provide a DLL / shared object along with your executable.

You can try to force a static link, but it will pollute your application using the LGPL license.

+3
source share

All Articles