From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 BB4A4BBAF for ; Fri, 6 Nov 2009 00:10:30 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AnUBAI/q8kpRZ90xkWdsb2JhbACbbwEBAQEJCwoHEwPEa4Q9BIt4 X-IronPort-AV: E=Sophos;i="4.44,688,1249250400"; d="scan'208";a="49874820" Received: from mtaout03-winn.ispmail.ntl.com ([81.103.221.49]) by mail4-smtp-sop.national.inria.fr with ESMTP; 06 Nov 2009 00:09:44 +0100 Received: from aamtaout03-winn.ispmail.ntl.com ([81.103.221.35]) by mtaout03-winn.ispmail.ntl.com (InterMail vM.7.08.04.00 201-2186-134-20080326) with ESMTP id <20091105230942.RACS17277.mtaout03-winn.ispmail.ntl.com@aamtaout03-winn.ispmail.ntl.com>; Thu, 5 Nov 2009 23:09:42 +0000 Received: from romulus.metastack.com ([81.102.132.77]) by aamtaout03-winn.ispmail.ntl.com (InterMail vG.2.02.00.01 201-2161-120-102-20060912) with ESMTP id <20091105230942.FFTB2093.aamtaout03-winn.ispmail.ntl.com@romulus.metastack.com>; Thu, 5 Nov 2009 23:09:42 +0000 Received: from Tenor ([172.16.0.8]) (authenticated bits=0) by romulus.metastack.com (8.14.2/8.14.2) with ESMTP id nA5N9YET031142 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NO); Thu, 5 Nov 2009 23:09:36 GMT From: "David Allsopp" To: "'Aaron Bohannon'" , References: In-Reply-To: Subject: RE: [Caml-list] compiling C library wrapper Date: Thu, 5 Nov 2009 23:09:38 -0000 Message-ID: <000001ca5e6d$0d6a0aa0$283e1fe0$@metastack.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Office Outlook 12.0 thread-index: AcpeZ9awjitDk9UhSLWThoy4DxI8+gABJxvw Content-Language: en-gb Organization: MetaStack Solutions Ltd. X-Scanned-By: MIMEDefang 2.65 on 81.102.132.77 X-Cloudmark-Analysis: v=1.0 c=1 a=kHNxsKtqaPIA:10 a=Pa7xJ7NTbpCngCy4BSUA:9 a=VGVPZ5NwZr3egXwn9qQA:7 a=0WokLJkwJLznlDES0rQQXN59cwUA:4 X-Spam: no; 0.00; wrappers:01 ocamlmklib:01 foo:01 foo:01 cmxa:01 ocamlopt:01 cmxa:01 lib:01 -cclib:01 usr:01 lib:01 ocaml:01 stubs:01 -cclib:01 stubs:01 Aaron Bohannon wrote: > I am quite confused by the whole process of compiling and installing > wrappers for C libraries. It seems like I can get things to work OK > without really knowing what I'm doing if everything is put and built > in a single directory. The hard part seems to be putting the right > files in the right places and getting the path arguments correct. > Then things stop working, and I have to really understand what's going > on, but the manual doesn't explain this part of the process in any > detail. Have a look at ocamlmklib in the manual - if it's available on your platform then it nicely hides away a lot of this. > 5) Write "foo.ml" and use it to build "foo.cmxa" by running > > ocamlopt -a -o foo.cmxa foo.ml > -ccopt -L/opt/local/lib -cclib -lfoo > -ccopt -L/usr/local/lib/ocaml/stubs -cclib -lfoo_stubs This command will also build foo.cmx, foo.a and foo.o > 6) Copy "foo.cmi" and "foo.cmxa" to their permanent location, let's > say "/usr/local/lib/ocaml/foo/" You should also copy foo.a to this directory which should fix the problem. foo.cmxa contains information required by OCaml but the actual code is in foo.a (as it's been natively compiled). Similarly, .cmx files contain information which ocamlopt needs but the actual code is in .o (or .obj) files. For native code, it's a code idea to copy the .cmx files too as it allows ocamlopt to do some inlining (I think that's right...) > 7) Write my file "bar.ml" that needs to use the library, and compile > it by running > > ocamlopt -I /usr/local/lib/ocaml/foo -o bar foo.cmxa bar.ml This should now work without error. David