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.1 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 7349EBBAF for ; Tue, 20 Jan 2009 18:22:37 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AiwBAJCWdUlQDPJhgWdsb2JhbACUBwEBCwkKBxMDt1GFcw X-IronPort-AV: E=Sophos;i="4.37,295,1231110000"; d="scan'208";a="19910327" Received: from smtp23.orange.fr ([80.12.242.97]) by mail2-smtp-roc.national.inria.fr with ESMTP; 20 Jan 2009 18:22:36 +0100 Received: from me-wanadoo.net (localhost [127.0.0.1]) by mwinf2359.orange.fr (SMTP Server) with ESMTP id 498E57000092; Tue, 20 Jan 2009 18:22:35 +0100 (CET) Received: from [192.168.1.66] (APuteaux-154-1-62-141.w81-249.abo.wanadoo.fr [81.249.69.141]) by mwinf2359.orange.fr (SMTP Server) with ESMTP id 1A2997000091; Tue, 20 Jan 2009 18:22:35 +0100 (CET) X-ME-UUID: 20090120172235107.1A2997000091@mwinf2359.orange.fr Message-ID: <4976085A.4010806@frisch.fr> Date: Tue, 20 Jan 2009 18:22:34 +0100 From: Alain Frisch User-Agent: Thunderbird 2.0.0.19 (Windows/20081209) MIME-Version: 1.0 To: John Whitington Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Building with OCamlMkLib References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Spam: no; 0.00; frisch:01 frisch:01 ocamlmklib:01 ocamlmklib:01 ocaml:01 ocamlc:01 -dnative:01 ocamlc:01 mli:01 cmxa:01 ocaml:01 runtime:01 -output-obj:01 -output-obj:01 cmo:01 John Whitington wrote: > Hi Folks, > > I'm building a Plain C interface to our PDF libraries, but am stuck. The > idea is to build a library with Ocamlmklib containing the C wrapper > around the ocaml code. > > I've used some test files (included below) in place of the real ones. > > I can successfully build the library (I'm using OS x / intel): > > ocamlc -c -cc "cc" -ccopt " -DNATIVE_CODE -o cpdflibwrapper.o" > cpdflibwrapper.c > ocamlc cpdflibc.mli > ocamlc cpdflibc.ml > ocamlmklib -o camlpdfc cpdflibc.ml cpdflibwrapper.a > > (builds dllcamlpdfc.so, camlpdfc.a, camlpdfc.cma, camlpdfc.cmxa) > > But trying to link a C program which uses the new library fails. Do I > need to include something else, or have I got the ocamlmklib stage wrong? You need to include an OCaml "main program" into your library. The easiest way to build a library that include the OCaml runtime, some OCaml code and custom C code is the -output-obj option: ocamlc -output-obj -o camlpdfc.so cpdlibc.cmo cpdflibwrapper.o Note that cpdflibrwrapper should define a function that calls caml_startup in order to start the OCaml runtime and run the OCaml code. If you want to build a static library, you can use "-output-obj -o camlpdf.o" and then create the library yourself. -- Alain