caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Compiling a native code OCaml library into an .so?
@ 2003-11-19 23:49 Aleksey Nogin
  2003-11-20  3:33 ` Kamil Shakirov
  0 siblings, 1 reply; 9+ messages in thread
From: Aleksey Nogin @ 2003-11-19 23:49 UTC (permalink / raw)
  To: caml-list

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


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2003-11-20 17:07 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-11-19 23:49 [Caml-list] Compiling a native code OCaml library into an .so? Aleksey Nogin
2003-11-20  3:33 ` Kamil Shakirov
2003-11-20  4:57   ` Aleksey Nogin
2003-11-20 11:13   ` [Caml-list] Caml as C-- (was: Compiling a native code OCaml library into an .so?) Oleg Trott
2003-11-20 11:30     ` Ville-Pertti Keinonen
2003-11-20 17:07       ` Oleg Trott
2003-11-20 11:46     ` Christian Lindig
2003-11-20 11:45       ` [Caml-list] Caml as C-- ZHAO Wei
2003-11-20 16:37       ` [Caml-list] Caml as C-- (was: Compiling a native code OCaml library into an .so?) Oleg Trott

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).