English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
[Caml-list] Compiling a native code OCaml library into an .so?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2003-11-20 (03:30)
From: Kamil Shakirov <kamils@i...>
Subject: Re: [Caml-list] Compiling a native code OCaml library into an .so?

> 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?

Look at the http://www.boblycat.org/~malc/scaml/


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