<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE message PUBLIC
  "-//MLarc//DTD MLarc output files//EN"
  "../../mlarc.dtd"[
  <!ATTLIST message
    listname CDATA #REQUIRED
    title CDATA #REQUIRED
  >
]>

  <?xml-stylesheet href="../../mlarc.xsl" type="text/xsl"?>


<message 
  url="2003/11/fb9d232a4943e8114fb8232e3f6e0533"
  from="Aleksey Nogin &lt;nogin@c...&gt;"
  author="Aleksey Nogin"
  date="2003-11-19T23:49:16"
  subject="[Caml-list] Compiling a native code OCaml library into an .so?"
  prev="2003/11/c17081509d394ca21766e84f62f3f830"
  next="2003/11/788a2c28afa9e9bc3bcf18dd0c33d1ab"
  next-in-thread="2003/11/3e56b235242226f208aa4773ba9575b9"
  prev-thread="2003/11/fa7fd7f24b1fa8fe03faf7957eab5c7b"
  next-thread="2003/11/a2140a10ae8f0fe8f4ff398f0fbd2ddc"
  root="../../"
  period="month"
  listname="caml-list"
  title="Archives of the Caml mailing list">

<thread subject="[Caml-list] Compiling a native code OCaml library into an .so?">
<msg 
  url="2003/11/fb9d232a4943e8114fb8232e3f6e0533"
  from="Aleksey Nogin &lt;nogin@c...&gt;"
  author="Aleksey Nogin"
  date="2003-11-19T23:49:16"
  subject="[Caml-list] Compiling a native code OCaml library into an .so?">
<msg 
  url="2003/11/3e56b235242226f208aa4773ba9575b9"
  from="Kamil Shakirov &lt;kamils@i...&gt;"
  author="Kamil Shakirov"
  date="2003-11-20T03:30:10"
  subject="Re: [Caml-list] Compiling a native code OCaml library into an .so?">
<msg 
  url="2003/11/4296b489fdc23a686237c0966d8b01c1"
  from="Aleksey Nogin &lt;nogin@c...&gt;"
  author="Aleksey Nogin"
  date="2003-11-20T04:57:17"
  subject="Re: [Caml-list] Compiling a native code OCaml library into an .so?">
</msg>
<msg 
  url="2003/11/fe1cf8257b6ab7bf556c839001ef56c6"
  from="Oleg Trott &lt;oleg_trott@c...&gt;"
  author="Oleg Trott"
  date="2003-11-20T11:13:32"
  subject="[Caml-list] Caml as C-- (was: Compiling a native code OCaml library into an .so?)">
<msg 
  url="2003/11/dfc877a22464b7360f04f9c9e84b646f"
  from="Ville-Pertti Keinonen &lt;will@e...&gt;"
  author="Ville-Pertti Keinonen"
  date="2003-11-20T11:30:46"
  subject="Re: [Caml-list] Caml as C-- (was: Compiling a native code OCaml library into an .so?)">
<msg 
  url="2003/11/a783473d302282d37390638ab8029dfa"
  from="Oleg Trott &lt;oleg_trott@c...&gt;"
  author="Oleg Trott"
  date="2003-11-20T17:07:33"
  subject="Re: [Caml-list] Caml as C-- (was: Compiling a native code OCaml library into an .so?)">
</msg>
</msg>
<msg 
  url="2003/11/7bfaea1d5af0f9ce57055a96a08b618c"
  from="Christian Lindig &lt;lindig@c...&gt;"
  author="Christian Lindig"
  date="2003-11-20T11:46:58"
  subject="Re: [Caml-list] Caml as C-- (was: Compiling a native code OCaml library into an .so?)">
<msg 
  url="2003/11/87e0f4fa442bd1c4cdaeaa3f188b670e"
  from="ZHAO Wei &lt;zhaoway@p...&gt;"
  author="ZHAO Wei"
  date="2003-11-20T12:01:54"
  subject="Re: [Caml-list] Caml as C--">
</msg>
<msg 
  url="2003/11/c3fd41ebe10e477e7c35b3f0f7cefdce"
  from="Oleg Trott &lt;oleg_trott@c...&gt;"
  author="Oleg Trott"
  date="2003-11-20T16:38:16"
  subject="Re: [Caml-list] Caml as C-- (was: Compiling a native code OCaml library into an .so?)">
</msg>
</msg>
</msg>
</msg>
</msg>
</thread>

<contents>
Hello all,

I am wondering - is it possible to compile a native code OCaml library 
into an dynamic library (.so) and then link an OCaml program against it, 
or dynamically load it from an OCaml program?

My (very shallow) understanding of how this is supposed to work suggests 
that it should not be too hard to implement (at least if we do not 
insist on detecting version mismatches at runtime). We would need:

1) A flag to ocamlopt that would tell it to compile to ".cmxa + .so" 
instead of ".cmxa + .a". Given such a flag, ocamlopt would
   a) Create an assembly file defining _init function that would call 
the initialization functions of all the modules and add that file to the 
list of things to be compiled in.
   b) Add -shared flag to the ld call.

2) When compiling a program with ocamlopt, if one of the arguments is a 
.cmxa, then look for both .a and .so and pass the right one to ld.

3) Have a function somewhere (Dynlink module?) that's a wrapper for the 
C's dlopen function.

4) Ideally - have a function somewhere (Dynlink module?) that would try 
loading a .cma when running in bytecode and would try loading an .so 
when running in native code.

Am I missing any serious difficulties here? Are there any plans to add 
something like this to OCaml?

-- 
Aleksey Nogin

Home Page: http://nogin.org/
E-Mail: nogin@cs.caltech.edu (office), aleksey@nogin.org (personal)
Office: Jorgensen 70, tel: (626) 395-2907

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners

</contents>

</message>

