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=0.0 required=5.0 tests=AWL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by yquem.inria.fr (Postfix) with ESMTP id 67577BC69 for ; Thu, 22 Nov 2007 18:21:36 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAANJIRUfB/BYflmdsb2JhbACPMAEBBwQGIgc X-IronPort-AV: E=Sophos;i="4.21,452,1188770400"; d="scan'208";a="4516781" Received: from smtp20.orange.fr ([193.252.22.31]) by mail2-smtp-roc.national.inria.fr with ESMTP; 22 Nov 2007 18:21:35 +0100 Received: from me-wanadoo.net (localhost [127.0.0.1]) by mwinf2022.orange.fr (SMTP Server) with ESMTP id B586F1C000BD for ; Thu, 22 Nov 2007 18:21:35 +0100 (CET) Received: from [192.168.1.59] (APuteaux-154-1-25-148.w83-199.abo.wanadoo.fr [83.199.80.148]) by mwinf2022.orange.fr (SMTP Server) with ESMTP id 7D0C01C000A0; Thu, 22 Nov 2007 18:21:35 +0100 (CET) X-ME-UUID: 20071122172135512.7D0C01C000A0@mwinf2022.orange.fr Message-ID: <4745BA90.9030104@frisch.fr> Date: Thu, 22 Nov 2007 18:21:20 +0100 From: Alain Frisch User-Agent: Thunderbird 2.0.0.9 (Windows/20071031) MIME-Version: 1.0 To: viktor tron Cc: Caml Mailing List Subject: Re: [Caml-list] C libs from Ocaml libs References: <8cc3d8520711202343q2951aee2lca188a185b84b511@mail.gmail.com> <4743FE39.9000208@frisch.fr> <8cc3d8520711210906k2c8ed0abg6f4305b275cddbf3@mail.gmail.com> <47446BE3.4070606@frisch.fr> <8cc3d8520711211035w6c9fa3a6je4622195e5a752af@mail.gmail.com> In-Reply-To: <8cc3d8520711211035w6c9fa3a6je4622195e5a752af@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Spam: no; 0.00; frisch:01 frisch:01 libs:01 ocaml:01 libs:01 ocaml:01 foo:01 ocamlopt:01 -output-obj:01 foo:01 cmxa:01 stub:01 lib:01 libfoo:01 gcc:01 viktor tron wrote: > 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 You are correct. > 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 What happens if you pass foo_caml.o instead of -lfoo? Can you send me (maybe off-list) a full set of files to reproduce the problem? > 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 I don't think that ar supports merging libraries like that. What can be done is to use "ld -r" (partial linking) to produce a single object file from libasmrun.a and foo_caml.o and then put this file in a library (or use it directly). > 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 Ok, that's a hack to merge one library, plus more object files into a library. I know it is mentioned in the OCaml manual. Personally, I would not recommend to do that (you'll be stuck if you need to include e.g. libunix.a). > In fact ocamlopt does pretty enigmatic things in the background Use the "-verbose" option to see what's going on. > and ar > is an entire mystery with this > copy thing. Use "ar t" to see what's in a library. -- Alain