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 mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by yquem.inria.fr (Postfix) with ESMTP id CC69CBC37 for ; Thu, 11 Feb 2010 12:16:25 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AqkZAMB1c0vD2MUqgWdsb2JhbACDCZBShx8VAQEWJCOsf49SgS+CTFsE X-IronPort-AV: E=Sophos;i="4.49,451,1262559600"; d="scan'208";a="44467871" Received: from bluelynx4.ukhost4u.com ([195.216.197.42]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 11 Feb 2010 12:16:25 +0100 Received: from [78.105.203.81] (helo=muscat.lan) by bluelynx4.ukhost4u.com with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.69) (envelope-from ) id 1NfX1z-0005Ai-4o for caml-list@yquem.inria.fr; Thu, 11 Feb 2010 11:16:23 +0000 Message-ID: <4B73E704.7040309@coherentgraphics.co.uk> Date: Thu, 11 Feb 2010 11:16:20 +0000 From: John Whitington User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.1.7) Gecko/20100111 Thunderbird/3.0.1 MIME-Version: 1.0 To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Ocaml, Objective-c, and XCode References: In-Reply-To: Content-Type: text/plain; charset=UTF-8; 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 - bluelynx4.ukhost4u.com X-AntiAbuse: Original Domain - yquem.inria.fr X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - coherentgraphics.co.uk X-Source: X-Source-Args: X-Source-Dir: X-Spam: no; 0.00; ocaml:01 ocaml:01 bindings:01 interfacing:01 haskell:01 haskell:01 makefile:01 compilation:01 flags:01 makefile:01 mklib:01 ocamlc:01 mli:01 ocamlopt:01 cmxa:01 Hi Andrew, On 11/02/2010 01:28, Andrew Webb wrote: > Hi there, > > I have a few questions relating to using Ocaml with objective-c for anyone who programs on a Mac. I am aware that there aren't any real bindings between ocaml and objective-c/cocoa, so I am investigating rolling my own. So: > > 1) Does anyone have experience in interfacing ocaml and objc? Is it difficult? > 2) Does anyone have a small example project that does mix these two languages? I have looked at unison, but it is too big for me to get my head around. I am thinking more on the scale of the ubiquitous Currency Converter... > 3) Does anyone who is mixing these languages use Xcode to do so? If so, what steps do you need to go through to set that up? > > A big thanks to anyone who can answer (some of) these questions. I am trying to decide whether to use haskell or ocaml for my next cocoa application, as these are the two languages I am most comfortable. I have recently found an excellent description of how to do this using haskell (http://tscheff.blogspot.com/2010/02/currync-converter-using-haskell-with.html) and was wondering if there were such resources for ocaml. I've just released a product written in this way: http://www.coherentpdf.com/proview.html I just have a normal makefile which builds a .a library from the ocaml code and its C wrapper as per the instructions in the ocaml manual. The xcode project then uses the .a and the .h of the wrapper and a few extra compilation and linking flags. Doubtless with a little bit more effort, Xcode could be made to call the ocaml makefile. Here's the OCaml makefile: mklib: ocamlc cpdf.mli; ocamlopt -c -I . unix.cmxa str.cmxa bigarray.cmxa cgutil.cmxa camlpdf.cmxa cpdf.ml; ocamlc cpdflib.mli; ocamlopt -c -I . unix.cmxa str.cmxa bigarray.cmxa cgutil.cmxa camlpdf.cmxa cpdf.cmx cpdflib.ml; ocamlc cpdflibc.mli; ocamlopt -c -I . unix.cmxa str.cmxa bigarray.cmxa cgutil.cmxa camlpdf.cmxa cpdf.cmx cpdflib.cmx cpdflibc.ml; ocamlc cpdflibwrapper.c; ocamlopt -output-obj -o cpdflibc.o unix.cmxa str.cmxa bigarray.cmxa cgutil.cmxa camlpdf.cmxa cpdf.cmx cpdflib.cmx cpdflibc.cmx; cp /usr/local/lib/ocaml/libasmrun.a cpdflib.a; ar r cpdflib.a cpdflibc.o cpdflibwrapper.o test: zlibstubs.o cpdflib.a cc -m32 -c cpdflibc-test.c -o cpdflibc-test.o; \ cc -m32 -L'/usr/local/lib/ocaml' -lunix -lbigarray -lstr -lz -o test cpdflibc-test.o zlibstubs.o cpdflib.a (The 'test' target shows you the kind of compiler and linker flags you'd need to put into XCode). Basically, once you've got the usual ocaml/c interface done, the Xcode part is no problem. Cheers, -- John Whitington Director, Coherent Graphics Ltd http://www.coherentpdf.com/