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.3 required=5.0 tests=AWL,HTML_MESSAGE,SPF_NEUTRAL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id 9E06DBC69 for ; Wed, 21 Nov 2007 19:35:07 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAJoJREdA6aayi2dsb2JhbACCPTaMQQEBAQgEBBMRBQ X-IronPort-AV: E=Sophos;i="4.21,447,1188770400"; d="scan'208";a="19546029" Received: from py-out-1112.google.com ([64.233.166.178]) by mail4-smtp-sop.national.inria.fr with ESMTP; 21 Nov 2007 19:35:06 +0100 Received: by py-out-1112.google.com with SMTP id u52so7581507pyb for ; Wed, 21 Nov 2007 10:35:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:references; bh=7Z3KNwn3qhZmRfDwBXMvVibhRdRDZFR7Oc90za3SDyE=; b=ge5xozxrMit6ryH3aGMLRrp+88iLsUcxh/6dOFu2yhm+109w8isBX135FjjcCMaIXuf63M7XsSya3l6++hHwl/OALoM/P5ndki7jRDkiNUJUvTELRuH3pAojjeARshcMXfttPxzG5P2JcH5MRkOPNQ/H4yo/lo4TW+3IVRXBYYs= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:references; b=jWHU01LCE8aN9NbJfZ2VGV6f6NsatPljdkvDR3DSPvTb331pdaZIvdE1qE6YNE6p+DDapU90CYIF0WXCOmjDSbnAhgtAShHkTogKlNfRqLjb4oSUUR/VrDs8WfdaHunQ/mEzWikBnOeigCOFe4loEPB4qWPXa7kVgYNipQEkQPc= Received: by 10.65.93.19 with SMTP id v19mr17427876qbl.1195670104986; Wed, 21 Nov 2007 10:35:04 -0800 (PST) Received: by 10.65.224.20 with HTTP; Wed, 21 Nov 2007 10:35:04 -0800 (PST) Message-ID: <8cc3d8520711211035w6c9fa3a6je4622195e5a752af@mail.gmail.com> Date: Wed, 21 Nov 2007 13:35:04 -0500 From: "viktor tron" To: "Caml Mailing List" Subject: Re: [Caml-list] C libs from Ocaml libs In-Reply-To: <47446BE3.4070606@frisch.fr> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_16363_7043907.1195670104964" References: <8cc3d8520711202343q2951aee2lca188a185b84b511@mail.gmail.com> <4743FE39.9000208@frisch.fr> <8cc3d8520711210906k2c8ed0abg6f4305b275cddbf3@mail.gmail.com> <47446BE3.4070606@frisch.fr> X-Spam: no; 0.00; libs:01 ocaml:01 libs:01 frisch:01 frisch:01 macos:01 powerpc:01 ocamlc:01 -output-obj:01 ocamlopt:01 -output-obj:01 foo:01 foo:01 stub:01 gcc:01 ------=_Part_16363_7043907.1195670104964 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline 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 > 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 > > > 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 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 ------=_Part_16363_7043907.1195670104964 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline

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 earlier (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/ocaml

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



------=_Part_16363_7043907.1195670104964--