Version française
Home     About     Download     Resources     Contact us    
Browse thread
Dynlink, libcamlrun and ocamlrun: How to load libraries with external C functions
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: EL CHAAR Rabih SGAM/AI/SAM <RABIH.ELCHAAR@s...>
Subject: Dynlink, libcamlrun and ocamlrun: How to load libraries with external C functions
Sorry for sending back the same post, but last one was in MIME format.


Hello everyone,

We have the following constraint:

We are planning to use an executable (let's name it A) from a
third-party, built upon ocaml.

It enables us to load our inhouse caml libraries via the Dynlink module.

The executable A is statically linked against libcamlrun.lib

Several of our libraries use external C functions, and we have them
built in two flavours : .cma for statically linked executables, and
_d.cma for loading via the toplevel (linked therefore with
ocamlrun.lib).

Our goal is to be able to load these libraries dynamically against A
(since we can't recompile A).

After making sure that the Dynlink module enables unsafe features, we
tried to load these libraries (_d.cma) and we were facing some access
violation exceptions.

After a thorough investigation, this seems to come from the fact that
our libraries were creating values with respect to ocamlrun runtime, and
the executable is expecting values with respect to libcamlrun runtime.
I'm not an expert on this issue (links are really appreciated), but
these two runtimes don't seem to share the same memory representation of
values (the exceptions were arising when calling from c functions like
caml_copy_double, ...).


This seems to point that it is not possible to use jointly libraries
with ocamlrun and libcamlrun runtimes, which is quite understandable.


We still need these libraries to be loaded dynamically, and they have
some external C functions. I have the impression that the only way to do
these is through linking with ocamlrun.lib and defining the CAML_DLL
symbol for the exported function using the Camlprim keyword.

I tried to switch the link library from ocamlrun to libcamlrun, but I
was having some undefined symbols 

b.obj : error LNK2019: unresolved external symbol __imp__caml_failwith
referenced in function ...
b.obj : error LNK2019: unresolved external symbol
__imp__caml_local_roots referenced in function ...
b.obj : error LNK2019: unresolved external symbol
__imp__caml_alloc_custom referenced in function ...
b.obj : error LNK2019: unresolved external symbol
__imp__caml_copy_double referenced in function ...

1)       Is there a way to create such libraries with the libcamlrun
runtime ?
2)       What is the correct approach to load libraries through Dynlink
with external functions ?
 
Thanks in advance for your help and advices.
If the post seems vague, please point it out and i'll give more
explanations or details.

Sincerely yours,
Rabih Chaar
Ce message et toutes les pieces jointes (ci-apres le "message") sont confidentiels et etablis a l'intention exclusive de ses destinataires. 
Toute utilisation ou diffusion non autorisee est interdite. 
Tout message electronique est susceptible d'alteration. 
Societe Generale Asset Management et ses filiales declinent toute responsabilite au titre de ce message s'il a ete altere, deforme ou falsifie. 
  
Decouvrez l'offre et les services de Societe Generale Asset Management sur le site www.sgam.fr 
  
                                ******** 
  
This message and any attachments (the "message") are confidential and intended solely for the addressees. 
Any unauthorised use or dissemination is prohibited. 
E-mails are susceptible to alteration. 
Neither Societe Generale Asset Management nor any of its subsidiaries or affiliates shall be liable for the message if altered, changed or falsified. 
 
Find out more about Societe Generale Asset Management's proposal on www.sgam.com