开发者

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?


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜