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

2

6

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?

Crossley answered 12/11, 2010 at 19:40 Comment(0)
B
7

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.

Bergin answered 13/11, 2010 at 3:26 Comment(0)
W
3

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.

Weldonwelfare answered 12/11, 2010 at 20:52 Comment(2)
Thanks for the reply. How do I know which .so I need to provide along with my executable? If I go for the static linking, how do I force a static link? Thanks!Crossley
It's not the camomile library that is dynamically loaded, but a number of its datafiles that hold unicode mappings for various character mappings.Anzac

© 2022 - 2024 — McMap. All rights reserved.