Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] dynamically loading C functions
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Fabrice Le Fessant <fabrice.le_fessant@i...>
Subject: Re: [Caml-list] dynamically loading C functions

I've written a Dlopen module for x86 and alpha available at
http://pauillac.inria.fr/~lefessan/src/dlopen.tar.gz

It allows this kind of thing:

 cremant:~/devel/dlopen%  ./top   
        Objective Caml version 3.00+9 (2000-07-08)

# open Dlopen;; 
# let dll = dlopen "./test.so"  [RTLD_NOW];;
val dll : Dlopen.dll = <abstr>
# let add_int = dlsym dll "add_int" "%d:%d%d";;
val add_int : int -> int -> int = <fun>
# let print_string = dlsym dll "print_string" "%d:%s";;
val print_string : string -> int = <fun>
# let add_double = dlsym dll "add_double" "%f:%f%f";;
val add_double : float -> float -> float = <fun>
# add_double (1.0) (2.0);;
x: 1.000000 y: 2.000000
- : float = 3.000000
# print_string "bonjour";;
bonjour
- : int = 10
# add_int 1 2;;
x: 1 y: 2
- : int = 3
# 

where test.c is:

#include <stdio.h>
#include <stdlib.h>

int add_int(int x, int y)
{  printf("x: %d y: %d\n",x,y); return x+y; }

int print_string(char *s)
{  printf("%s\n", s);  return 10;}

double add_double(double x, double y)
{ printf("x: %f y: %f\n",x,y); return x+y;}

- Fabrice
-------------------
To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr