From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 4CDB5BB84 for ; Tue, 18 Apr 2006 15:31:44 +0200 (CEST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id k3IDVhGo003543 for ; Tue, 18 Apr 2006 15:31:43 +0200 Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id PAA15656 for ; Tue, 18 Apr 2006 15:31:42 +0200 (MET DST) Received: from parmail03.sgcib.com (parmail03.sgcib.com [207.45.250.36]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id k3IDVfER003533 for ; Tue, 18 Apr 2006 15:31:41 +0200 X-IronPort-AV: i="4.04,131,1144015200"; d="scan'208,217"; a="5671356:sNHT62511404" Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----_=_NextPart_001_01C662EC.6C97A5A0" X-MimeOLE: Produced By Microsoft Exchange V6.5.7226.0 Subject: Dynlink, libcamlrun and ocamlrun: How to load libraries with external C functions Date: Tue, 18 Apr 2006 15:31:40 +0200 Message-ID: <7F070E410B10EE419826BF5206322CC2095265@frdef-exmb01.europe.am.socgen> Thread-Topic: Dynlink, libcamlrun and ocamlrun: How to load libraries with external C functions Thread-Index: AcZi7GyhUrxGl9w3Q4anNrMtsQV7ZQ== From: "EL CHAAR Rabih SGAM/AI/SAM" To: X-OriginalArrivalTime: 18 Apr 2006 13:31:39.0969 (UTC) FILETIME=[6C8E0B10:01C662EC] X-NAI-Spam-Rules: 2 Rules triggered BAYES_01=-1.2, HTML_MESSAGE=0 X-j-chkmail-Score: MSGID : 4444EA3F.000 on concorde : j-chkmail score : XXX : 5/20 1 X-j-chkmail-Score: MSGID : 4444EA3D.000 on concorde : j-chkmail score : XXX : 5/20 1 X-Miltered: at concorde with ID 4444EA3F.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at concorde with ID 4444EA3D.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; dynlink:01 libcamlrun:01 ocamlrun:01 ocaml:01 dynlink:01 statically:01 libcamlrun:01 lib:01 statically:01 toplevel:01 ocamlrun:01 lib:01 recompile:01 runtime:01 runtime:01 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=HTML_60_70,HTML_MESSAGE autolearn=disabled version=3.0.3 This is a multi-part message in MIME format. ------_=_NextPart_001_01C662EC.6C97A5A0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="us-ascii" Hello everyone, =20 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 =20 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). =20 Our goal is to be able to load these libraries dynamically against A (since we can't recompile A). =20 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, ...). =20 This seems to point that it is not possible to use jointly libraries with ocamlrun and libcamlrun runtimes, which is quite understandable. =20 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. =20 I tried to switch the link library from ocamlrun to libcamlrun, but I was having some undefined symbols=20 =20 b=2Eobj : error LNK2019: unresolved external symbol __imp__caml_failwith referenced in function ... b=2Eobj : error LNK2019: unresolved external symbol __imp__caml_local_roots referenced in function ... b=2Eobj : error LNK2019: unresolved external symbol __imp__caml_alloc_custom referenced in function ... b=2Eobj : error LNK2019: unresolved external symbol __imp__caml_copy_double referenced in function ... =20 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 ? =20 =20 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, =20 Rabih Chaar Ce message et toutes les pieces jointes (ci-apres le "message") sont confid= entiels et etablis a l'intention exclusive de ses destinataires.=20 Toute utilisation ou diffusion non autorisee est interdite.=20 Tout message electronique est susceptible d'alteration.=20 Societe Generale Asset Management et ses filiales declinent toute responsab= ilite au titre de ce message s'il a ete altere, deforme ou falsifie.=20 =20 Decouvrez l'offre et les services de Societe Generale Asset Management sur = le site www.sgam.fr=20 =20 ********=20 =20 This message and any attachments (the "message") are confidential and inten= ded solely for the addressees.=20 Any unauthorised use or dissemination is prohibited.=20 E-mails are susceptible to alteration.=20 Neither Societe Generale Asset Management nor any of its subsidiaries or af= filiates shall be liable for the message if altered, changed or falsified.=20 =20 Find out more about Societe Generale Asset Management's proposal on www.sga= m=2Ecom ------_=_NextPart_001_01C662EC.6C97A5A0 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset="us-ascii"

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 executa= bles, and _d.cma for loading via the toplevel (linked therefore with ocamlrun.lib= )=2E

 

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 faci= ng some access violation exceptions.

After a thorough investigation, this seems to come from the fact that our libraries were creating values with respect to ocaml= run runtime, and the executable is expecting values with respect to libcamlrun runtime. I’m not an expert on this issue (links are really appreciate= d), but these two runtimes don’t seem to share the same memory representa= tion 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 defi= ning 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 libcaml= run 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 c=
onfidentiels et etablis a l'intention exclusive de ses destinataires.=20
Toute utilisation ou diffusion non autorisee est interdite.=20
Tout message electronique est susceptible d'alteration.=20
Societe Generale Asset Management et ses filiales declinent toute responsab=
ilite au titre de ce message s'il a ete altere, deforme ou falsifie.=20
 =20
Decouvrez l'offre et les services de Societe Generale Asset Management sur =
le site www.sgam.fr=20
 =20
                                ********=20
 =20
This message and any attachments (the "message") are confidential and inten=
ded solely for the addressees.=20
Any unauthorised use or dissemination is prohibited.=20
E-mails are susceptible to alteration.=20
Neither Societe Generale Asset Management nor any of its subsidiaries or af=
filiates shall be liable for the message if altered, changed or falsified.=20
=20
Find out more about Societe Generale Asset Management's proposal on www.sga=
m=2Ecom
------_=_NextPart_001_01C662EC.6C97A5A0--