From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by sympa.inria.fr (Postfix) with ESMTPS id 9156E7EE43 for ; Fri, 14 Jun 2013 12:55:06 +0200 (CEST) Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of d0@wp.pl) identity=pra; client-ip=80.91.229.3; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="gclci-caml-list@m.gmane.org"; x-sender="d0@wp.pl"; x-conformance=sidf_compatible Received-SPF: Pass (mail3-smtp-sop.national.inria.fr: domain of gclci-caml-list@m.gmane.org designates 80.91.229.3 as permitted sender) identity=mailfrom; client-ip=80.91.229.3; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="gclci-caml-list@m.gmane.org"; x-sender="gclci-caml-list@m.gmane.org"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: Pass (mail3-smtp-sop.national.inria.fr: domain of postmaster@plane.gmane.org designates 80.91.229.3 as permitted sender) identity=helo; client-ip=80.91.229.3; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="gclci-caml-list@m.gmane.org"; x-sender="postmaster@plane.gmane.org"; x-conformance=sidf_compatible; x-record-type="v=spf1" X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AkcAAOf1ulFQW+UDmWdsb2JhbABagzmDSLxhFg4BAQEBAQgLCwcUKIIjAQEFIw8BVgkCGAICGA4CAhBHEwgCh3cBEgSNOJs9iB4eiQuBJo4/gjaBFAOsFA X-IPAS-Result: AkcAAOf1ulFQW+UDmWdsb2JhbABagzmDSLxhFg4BAQEBAQgLCwcUKIIjAQEFIw8BVgkCGAICGA4CAhBHEwgCh3cBEgSNOJs9iB4eiQuBJo4/gjaBFAOsFA X-IronPort-AV: E=Sophos;i="4.87,865,1363129200"; d="scan'208";a="17804757" Received: from plane.gmane.org ([80.91.229.3]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/AES256-SHA; 14 Jun 2013 12:55:05 +0200 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1UnRep-00077s-1d for caml-list@inria.fr; Fri, 14 Jun 2013 12:55:03 +0200 Received: from ifjdh227.ifj.edu.pl ([149.156.47.227]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 14 Jun 2013 12:55:03 +0200 Received: from d0 by ifjdh227.ifj.edu.pl with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 14 Jun 2013 12:55:03 +0200 X-Injected-Via-Gmane: http://gmane.org/ To: caml-list@inria.fr From: Dawid Toton Date: Fri, 14 Jun 2013 12:16:58 +0200 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: ifjdh227.ifj.edu.pl User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0.12) Gecko/20130116 Icedove/10.0.12 In-Reply-To: X-Enigmail-Version: 1.4.1 Subject: [Caml-list] Re: OCaml binary formats -- how are they linked? On 06/14/2013 11:30 AM, Ömer Sinan Ağacan wrote: > Hi all, > > Let's say I have a C API called from OCaml. Bindings are compiled > to .cma, .cmx, .cmxa files. > > What I'm wondering is that are those C objects linked to those > binary files statically or dynamically? > Depending on what you do, some objects can be dynamically linked to an OCaml program. Since OCaml←→C interface requires the C code to follow the rules and use the provided headers (like mlvalues.h), in practice an extra layer of code is usually added: ---- normal OCaml stuff: a.ml → a.cmx + a.o ---- OCaml modules with "external" functions b.ml → b.cmx + b.o ---- the extra layer of C code: wrappers.c → wrappers.o ---- the actural C code that doesn't care about special OCaml needs: foo.c → foo.o ---- The OCaml compiler includes b.o and every other compiled OCaml module in the executable. wrappers.o and foo.o can end up as a part of dynamically linked library, but you have choice. You can even call the linker directly and play weird things with all the *.o files that C and OCaml compilers produce. Dawid