Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Shared libraries again
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: malc <malc@p...>
Subject: Re: [Caml-list] Shared libraries again
On 21 Sep 2002, Dmitry Lomov wrote:

> Hi,
> is it possible build a shared C library which calls Caml code? It is OK
> if shared library uses Caml runtime statically. I do not need to 
> call Caml runtime from different shared libraries - only from one,
> and it is OK for me if Caml values will be invalid outside shared
> library. That is, my shared library wholly controls Caml runtime
> startup.

*** Makefile
main: lib.so sh_c.o
        cc -o $@ $+ -Wl,-rpath,.

lib.so: sh.ml
        ocamlopt -c sh.ml
        ocamlopt -o $@ -cclib -shared sh.cmx

sh_c.o: sh_c.c
        ocamlc -o $@ -c $<

*** sh_c.c
#include <stdio.h>
#include <caml/mlvalues.h>
#include <caml/callback.h>

int main (int argc, char **argv)
{
  caml_startup(argv);
  callback (*caml_named_value ("ml_func"), Val_unit);
  return 0;
}

*** sh.ml
let ml_func () =
  print_string "moo";
  print_newline ()

let _ = Callback.register "ml_func" ml_func

-- 
mailto:malc@pulsesoft.com

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