From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: * X-Spam-Status: No, score=1.4 required=5.0 tests=AWL,HTML_MESSAGE,NO_REAL_NAME, SPF_NEUTRAL autolearn=disabled version=3.1.3 Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by yquem.inria.fr (Postfix) with ESMTP id 69AB9BC69 for ; Thu, 22 Nov 2007 17:42:09 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAKlARUfPLfoknmdsb2JhbACCc4tHdgEBBwQGKYEP X-IronPort-AV: E=Sophos;i="4.21,452,1188770400"; d="scan'208,217";a="6082864" Received: from parmail03.sgcib.com ([207.45.250.36]) by mail3-smtp-sop.national.inria.fr with ESMTP; 22 Nov 2007 17:42:08 +0100 X-IronPort-AV: i="4.21,452,1188770400"; d="scan'208,217"; a="186083236:sNHT1357929292" Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----_=_NextPart_001_01C82D26.93E44ADF" X-MimeOLE: Produced By Microsoft Exchange V6.5.7226.0 Subject: RE: [Caml-list] C libs from Ocaml libs Date: Thu, 22 Nov 2007 17:41:49 +0100 Message-ID: <0172C3AE3A0E964797AF43E206C1048F0ED53C@FRCOR-EXMB06.europe.am.socgen> X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: [Caml-list] C libs from Ocaml libs Thread-Index: AcgsbUdvxHHkUaVyRIOAuy8IO1boswAuIM8g From: To: , X-OriginalArrivalTime: 22 Nov 2007 16:41:50.0305 (UTC) FILETIME=[94796510:01C82D26] X-NAI-Spam-Rules: 1 Rules triggered BAYES_01=-1.2 X-Spam: no; 0.00; libs:01 ocaml:01 libs:01 cmxa:01 lib:01 appending:01 makefile:01 dirs:01 camljava:01 gsl:01 cmxa:01 jni:01 lib:01 libpath:01 ocamllib:01 This is a multi-part message in MIME format. ------_=_NextPart_001_01C82D26.93E44ADF Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hello Viktor, I think that some libraries are missing in the link phase. =20 When a x.cmxa is generated, a x.lib is also generated. You need to pass it = to the linker when you are generating a c executable or dll, even if you us= e the .cmxas in your output-obj, because all the relevant code is not just = there. =20 I am appending the makefile of some internal code that generated a C Win32 = dll. =20 Hope this helps. =20 JAVA_INC=3D$(JNIINCLUDES) DIRS=3D-w y -w p -I +camljava -I +gsl -I +schedule -I +ocamlDM -I ../common= / =20 LIBS=3Drschedule.cmxa ocamlDMManager.cmxa jni_init.cmxa common.cmxa=20 all: Engine.dll =20 install: all cp Engine.dll ../../bin =20 # supposes that the linker has access to the j2sdk lib # rabih /libpath:"d:/appli/j2sdk1.4.1_05/lib"=20 Engine.dll: ocamllib.obj Engine.obj link /nologo /dll /out:Engine.dll \ /libpath:$(OCAML_LIB) /libpath:$(OCAML_CAMLJAVA) /libpath:$(JDK= HOME)/lib \ /libpath:$(OCAML_LIB)/schedule /libpath:$(OCAML_LIB)/ocamlDM /l= ibpath:$(OCAML_LIB)/gsl /NODEFAULTLIB:libc \ jvm.lib jni.lib rschedule.lib ocamlDMManager.lib \ Engine.obj ocamllib.obj \ libasmrun.lib libcamljni.lib =20 Engine.obj: Engine.h Engine.c cl /c $(JAVA_INC) -I$(OCAML_LIB) Engine.c =20 =20 %=2Ecmx: %.mf ocamlopt $(DIRS) -c -dtypes $< =20 =20 ocamllib.obj:ocaml _Engine.cmx ocamlopt -dtypes $(DIRS) -output-obj -o ocamllib.obj $(LIBS) $^ =20 depend: echo -n > .depend ocamldep $(DIRS) ocaml_Engine.mf >.depend =20 clean: rm -f *.obj rm -f *.dll rm -f *.lib rm -f *.exp rm -f *.cm* rm -f *.h rm -f *~ =20 include .depend include ../Makefile.config =20 ________________________________ De : caml-list-bounces@yquem.inria.fr [mailto:caml-list-bounces@yquem.inria= .fr] De la part de viktor tron Envoy=E9 : mercredi 21 novembre 2007 19:35 =C0 : Caml Mailing List Objet : Re: [Caml-list] C libs from Ocaml libs =20 =20 On 21/11/2007, Alain Frisch wrote: viktor tron wrote: > This is super! how is this on MacOS, I recall one of your comment earlier= (on this list?) > that it doesn't work or something. Everything should work fine under Mac OS X x86. For PowerPC, I believe=20 that "ocamlc -output-obj -o XXX.so" should be ok but that "ocamlopt -output-obj -o XXX.so" does not work. > well, I tried. > ar -rs foo_caml.o foo_stub.o > gcc -o foo_test.native foo_test.c -L. -lchainfreq_native -L/sw/lib/ocaml=20 What is the name of the library you want to produce? sorry, let me be very explicit then: 0)=20 I believed that the following=20 creates the c object containing:=20 (a) main ocaml implementation of foo (b) export API (c) C binding to API (d= ) ocaml startup code=20 $ ocamlopt -output-obj -o foo_caml.o foo.cmxa foo_stub.c foo_export.ml now I create a lib $ ar rs libfoo.a foo_caml.o and happy ever after. Nope. No matter how I link it with a main c test, I get undefined symbols for sta= rtup code=20 $ gcc -o foo_test foo_test.c -L. -lfoo -lasmrun In fact, the following variants don't work: 1)=20 $ ocamlopt -output-obj -o foo_caml.o foo.cmxa foo_stub.c foo_export.ml $ ar -rs libfoo.a /sw/lib/ocaml/libasmrun.a foo_caml.o=20 $ gcc -o foo_test foo_test.c -L. -lfoo 2) $ ocamlopt -output-obj -o foo_caml.o foo.cmxa foo_stub.c foo_export.ml $ cp /sw/lib/ocaml/libasmrun.a libfoo.a=20 $ ar -rs libfoo.a foo_caml.o=20 $ gcc -o foo_test foo_test.c -L. -lfoo=20 so it seems I have to compile foo_stub.o separately... but even if I do: 3) $ ocamlopt -output-obj -o foo_caml.o foo.cmxa foo_stub.c foo_export.ml $ ocamlopt foo_stub.c $ ar -rs libfoo.a foo_caml.o foo_stub.o=20 $ gcc -o foo_test foo_test.c -L. -lfoo -L/sw/lib/ocaml -lasmrun 4) $ ocamlopt -output-obj -o foo_caml.o foo.cmxa foo_stub.c foo_export.ml $ ocamlopt foo_stub.c $ ar -rs libfoo.a /sw/lib/ocaml/libasmrun.a foo_caml.o=20 $ gcc -o foo_test foo_test.c -L. -lfoo both fail, the only thing that works is when (a) I compile stub and caml objects separately AND=20 (b) use copy to bootstrap the runtime $ ocamlopt -output-obj -o foo_caml.o foo.cmxa foo_stub.c foo_export.ml $ ocamlopt foo_stub.c $ cp /sw/lib/ocaml/libasmrun.a libfoo.a=20 $ ar -rs libfoo.a foo_caml.o foo_stub.o $ gcc -o foo_test foo_test.c -L. -lfoo In fact ocamlopt does pretty enigmatic things in the background and ar is a= n entire mystery with this=20 copy thing.=20 If anyone can make me understand the above, I'd be forever grateful. thanks Viktor =20 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_01C82D26.93E44ADF Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable

Hello Viktor,<= /o:p>

I think that some libraries are missing in the link phase.

 

When a x.cmxa is generated, a x.lib is also generated. You need to pass it to the linker when you are generating a c executable or dll, even if you use the .cmxas in your output-obj, because all the relevant code is not just there.

 

I am appending the makefile of some internal code that generated a C Win32 dll.

 

Hope this helps.

 

JAVA_INC=3D$(JNIINC= LUDES)

DIRS=3D-w y -w p -I= +camljava -I +gsl -I +schedule -I +ocamlDM -I ../common/=A0=A0=A0=A0=A0=A0=A0

LIBS=3Drschedule.cm= xa ocamlDMManager.cmxa jni_init.cmxa common.cmxa

all: Engine.dll

 

install: all

=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0 cp Engine.dll .=2E/../bin

 

# supposes that the linker has access to the j2sdk lib

# rabih /libpath:&q= uot;d:/appli/j2sdk1.4.1_05/lib"

Engine.dll: ocamlli= b=2Eobj Engine.obj

=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0 link /nologo /dll /out:Engine.dll \

=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0 /libpath:$(OCAML_LIB) /libpath:$(OCAML_CAMLJAVA) /libpath:$(JDKHOME)/lib \

=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0 /libpath:$(OCAML_LIB)/schedule /libpath:$(OCAML_LIB)/ocamlDM /libpath:$(OCAML_LIB)/gsl /NODEFAULTLIB:libc = \

=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0 jvm.lib jni.lib=A0 rschedule.lib ocamlDMManager.lib \

=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0 Engine.obj=A0 ocamllib.obj \

=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0 libasmrun.lib libcamljni.lib

 

Engine.obj: Engine.h Engine.c

=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0 cl /c $(JAVA_INC) -I$(OCAML_LIB) Engine.c

 

 

%.cmx: %.mf

=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 ocam= lopt $(DIRS) -c -dtypes $<

 

 

ocamllib.obj:ocaml _Engine.cmx

=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 ocam= lopt -dtypes $(DIRS) -output-obj -o ocamllib.obj=A0 $(LIBS) $^

 

depend:<= /span>

=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0 echo -n > .depend

=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0 ocamldep $(DIRS) ocaml_Engine.mf >.depend

 

clean:

=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0 rm -f *.obj

=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0 rm -f *.dll

=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0 rm -f *.lib

=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0 rm -f *.exp

=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0 rm -f *.cm*

=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0 rm -f *.h

=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0 rm -f *~

 

include .depend

include ../Makefile= .config

 


De : caml-list-bounces@yquem.inria.fr [mailto:caml-list-bounces@yquem.inria.fr] = De la part de viktor tron
Envoy=E9 : mercredi 21 = novembre 2007 19:35
=C0 : Caml Mailing List=
Objet : Re: [Caml-list]= C libs from Ocaml libs

 

 =

On 21/11/2007, Alain Frisch <= alain@frisch.fr > wrote:

viktor tron wrote:
> This is super! how is this on MacOS, I recall one of your comment earl= ier (on this list?)
> that it doesn't work or something.

Everything should work fine under Mac OS X x86. For PowerPC, I believe
that "ocamlc -output-obj -o XXX.so" should be ok but that "ocamlopt
-output-obj -o XXX.so" does not work.

> well, I tried.
> ar -rs foo_caml.o foo_stub.o
> gcc -o foo_test.native foo_test.c -L. -lchainfreq_native -L/sw/lib/oca= ml

What is the name of the library you want to produce?


sorry, let me be very explicit then:

0)
I believed that the following
creates the c object containing:
(a) main ocaml implementation of foo (b) export API (c) C binding to API (d) ocaml startup code

$ ocamlopt -output-obj -o foo_caml.o foo.cmxa foo_stub.c foo_export.ml=

now I create a lib

$ ar rs libfoo.a foo_caml.o

and happy ever after. Nope.
No matter how I link it with a main=  c test, I get undefined symbols for&nbs= p;startup code

$ gcc -o foo_test foo_test.c -L. -lfoo -lasmrun

In fact, the following variants don't work:

1)
$ ocamlopt -output-obj -o foo_caml.o foo.cmxa foo_stub.c foo_export.ml
$ ar -rs libfoo.a /sw/lib/ocaml/libasmrun.a foo_caml.o
$ gcc -o foo_test foo_test.c -L. -lfoo

2)
$ ocamlopt -output-obj -o foo_caml.o foo.cmxa foo_stub.c foo_export.ml
$ cp /sw/lib/ocaml/libasmrun.a libfoo.a
$ ar -rs libfoo.a foo_caml.o
$ gcc -o foo_test foo_test.c -L. -lfoo

so it seems I have to compile foo_stub.o separately...

but even if I do:

3)
$ ocamlopt -output-obj -o foo_caml.o foo.cmxa foo_stub.c foo_export.ml
$ ocamlopt foo_stub.c
$ ar -rs libfoo.a foo_caml.o foo_stub.o
$ gcc -o foo_test foo_test.c -L. -lfoo -L/sw/lib/ocaml -lasmrun

4)
$ ocamlopt -output-obj -o foo_caml.o foo.cmxa foo_stub.c foo_export.ml
$ ocamlopt foo_stub.c
$ ar -rs libfoo.a /sw/lib/ocaml/libasmrun.a foo_caml.o
$ gcc -o foo_test foo_test.c -L. -lfoo

both fail, the only thing that works is when
(a) I compile stub and caml objects separately AND 
(b) use copy to bootstrap the runtime

$ ocamlopt -output-obj -o foo_caml.o foo.cmxa foo_stub.c foo_export.ml
$ ocamlopt foo_stub.c
$ cp /sw/lib/ocaml/libasmrun.a libfoo.a
$ ar -rs libfoo.a foo_caml.o foo_stub.o
$ gcc -o foo_test foo_test.c -L. -lfoo

In fact ocamlopt does pretty enigmatic things in the background and ar is an entire mystery with this
copy thing.
If anyone can make me understand the above, I'd be forever grateful.

thanks
Viktor

 =

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_01C82D26.93E44ADF--