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 C137A820A1 for ; Tue, 27 Aug 2013 15:12:37 +0200 (CEST) Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of john@coherentgraphics.co.uk) identity=pra; client-ip=188.64.184.40; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="john@coherentgraphics.co.uk"; x-sender="john@coherentgraphics.co.uk"; x-conformance=sidf_compatible Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of john@coherentgraphics.co.uk) identity=mailfrom; client-ip=188.64.184.40; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="john@coherentgraphics.co.uk"; x-sender="john@coherentgraphics.co.uk"; x-conformance=sidf_compatible Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@bluechip4.ukhost4u.com) identity=helo; client-ip=188.64.184.40; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="john@coherentgraphics.co.uk"; x-sender="postmaster@bluechip4.ukhost4u.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: As0FAFOkHFK8QLgoY2dsb2JhbABagwc1wHSBJhYDGAcOCDyCJAEBBAE4QAEFCwsHBwoJEwMPCQMCAQIBRQYOiAAKCLhlj2QHhBkDmRyTVA X-IPAS-Result: As0FAFOkHFK8QLgoY2dsb2JhbABagwc1wHSBJhYDGAcOCDyCJAEBBAE4QAEFCwsHBwoJEwMPCQMCAQIBRQYOiAAKCLhlj2QHhBkDmRyTVA X-IronPort-AV: E=Sophos;i="4.89,968,1367964000"; d="scan'208";a="24899635" Received: from bluechip4.ukhost4u.com ([188.64.184.40]) by mail3-smtp-sop.national.inria.fr with ESMTP; 27 Aug 2013 15:12:37 +0200 Received: from 78-105-203-81.zone3.bethere.co.uk ([78.105.203.81]:62547 helo=feast.local) by bluechip4.ukhost4u.com with esmtpa (Exim 4.80.1) (envelope-from ) id 1VEJ4V-003u7f-L4; Tue, 27 Aug 2013 14:12:35 +0100 Message-ID: <521CA5C3.5030007@coherentgraphics.co.uk> Date: Tue, 27 Aug 2013 14:12:35 +0100 From: John Whitington User-Agent: Postbox 3.0.8 (Macintosh/20130427) MIME-Version: 1.0 To: Gerd Stolpmann CC: caml users References: <52164BAE.3080509@coherentgraphics.co.uk> <1377210265.18270.4.camel@e130> In-Reply-To: <1377210265.18270.4.camel@e130> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - bluechip4.ukhost4u.com X-AntiAbuse: Original Domain - inria.fr X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - coherentgraphics.co.uk X-Get-Message-Sender-Via: bluechip4.ukhost4u.com: authenticated_id: john@coherentgraphics.co.uk Subject: Re: [Caml-list] Building a mixed C / OCaml static library to be used from C Hi, Gerd Stolpmann wrote: > Am Donnerstag, den 22.08.2013, 18:34 +0100 schrieb John Whitington: >> Hi, >> >> I have the following recipe to build a static library of C functions >> from a mixed ocaml / c codebase. The idea is that the final linking step >> to build target 'test' won't require any special flags: >> >> >> CAMLBASE = /Users/john/.opam/4.00.1/lib/ >> >> mklib: cpdflib.mli cpdflib.ml cpdflibwrapper.c >> ocamlfind ocamlc -package cpdf cpdflib.mli; >> ocamlfind ocamlopt -package cpdf -c cpdflib.ml; >> ocamlfind ocamlc cpdflibwrapper.c; >> ocamlfind ocamlopt -I $(CAMLBASE)cpdf -I $(CAMLBASE)camlpdf \ >> -output-obj -o cpdflib.o \ >> unix.cmxa bigarray.cmxa camlpdf.cmxa cpdf.cmxa cpdflib.cmx; >> ar -x $(CAMLBASE)camlpdf/libcamlpdf_stubs.a; >> ar -x $(CAMLBASE)ocaml/libasmrun.a; >> ar cr cpdflib.a *.o >> >> test: cpdflib.a cpdflibtest.c >> cc cpdflibtest.c cpdflib.a -o test\ >> -L $(CAMLBASE)ocaml -lbigarray -lunix >> >> clean: >> rm __.SYMDEF\ SORTED *.o *.cmx *.cmi *.a test >> >> >> (Here, cpdflib.ml, cpdflib.mli and cpdflibwrapper.c form the C interface >> to the OCaml functions. cpdflibtest.c calls caml_startup and then any >> caml functions it likes). >> >> This works. However, I'm having trouble getting rid of "-L >> $(CAMLBASE)ocaml -lbigarray -lunix" -- i'd like the person linking with >> my cpdflib.a not to need any dependencies at all. >> >> When I add two more lines >> >> ar -x $(CAMLBASE)ocaml/bigarray.a; >> ar -x $(CAMLBASE)ocaml/unix.a; > > These are the wrong two libs. bigarray.a and unix.a are already > contained in cpdflib.a. What you need are libbigarray.a and libunix.a. Ah. A schoolboy error. Thanks! However, it looks like this might not be possible anyway. In this thread... http://caml.inria.fr/pub/ml-archives/caml-list/2007/11/c0ce27aa2dd792643615b6b705750657.en.html ...Alain Frisch comments on the method above, saying: > 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). So, unless I can find a way to get partial linking with ld -r to work, the best I have for now is: CAMLBASE = /Users/john/.opam/4.00.1/lib/ mklib: cpdflib.mli cpdflib.ml cpdflibwrapper.c ocamlfind ocamlc -package cpdf cpdflib.mli; ocamlfind ocamlopt -package cpdf -c cpdflib.ml; ocamlfind ocamlc cpdflibwrapper.c; ocamlfind ocamlopt -I $(CAMLBASE)cpdf -I $(CAMLBASE)camlpdf \ -output-obj -o cpdflib.o \ unix.cmxa bigarray.cmxa camlpdf.cmxa cpdf.cmxa cpdflib.cmx; cp $(CAMLBASE)ocaml/libasmrun.a libcpdf.a; ar -x $(CAMLBASE)camlpdf/libcamlpdf_stubs.a; ar r libcpdf.a *.o test: libcpdf.a cpdflibtest.c cc cpdflibtest.c -o test -L. -lcpdf -lbigarray -lunix clean: rm __.SYMDEF\ SORTED *.o *.cmx *.cmi *.a test The end-user of the library still needs three -l options, but I need only ship the three .a files (libcpdf, libbigarray, libunix), which I suppose is not much harder on the end user than shipping one. Obviously, I hope most people will be building from source, but I do need to ship binary libraries too. Thanks, -- John Whitington Director, Coherent Graphics Ltd http://www.coherentpdf.com/