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.0 required=5.0 tests=none autolearn=disabled version=3.1.3 Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by yquem.inria.fr (Postfix) with ESMTP id 7DBFCBB84 for ; Sun, 28 Sep 2008 00:53:53 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ApgAAPBV3kjRVcivlGdsb2JhbACSdz4BAQEBCQkMBxEDnwKGbAECfQGCZQ X-IronPort-AV: E=Sophos;i="4.33,322,1220220000"; d="scan'208";a="17422249" Received: from wf-out-1314.google.com ([209.85.200.175]) by mail3-smtp-sop.national.inria.fr with ESMTP; 28 Sep 2008 00:53:52 +0200 Received: by wf-out-1314.google.com with SMTP id 24so1705167wfg.15 for ; Sat, 27 Sep 2008 15:53:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:sender :to:subject:cc:in-reply-to:mime-version:content-type :content-transfer-encoding:content-disposition:references :x-google-sender-auth; bh=M6wkhT9UDSYRDN2ucI87KU0f3r6o5JFNZ6y5Eh8dOS0=; b=OO0GZLEBayj4CN5Q6zZFU6z7Zzn94lGbgjmlvMRIZ4B+JM2zUb8HXnImuRqr0PQn76 TrdsBKDhzYBVXhEgB+3l/6zRJF8o5Hr35I6edzMWkPuDWdtc29Fl1fRPQfQ3NmCkv8NP pHtpQO3zJoXJt1E6dFPoIqaGomrAr+DXDWEMA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:sender:to:subject:cc:in-reply-to:mime-version :content-type:content-transfer-encoding:content-disposition :references:x-google-sender-auth; b=Zt50EzplnZl32UtOU+Hete6fanwQDlWMUljBiGvO4DBdtzoRw/sJrRcZNNLsZnXrWS lzevi9y1DYlYiysxjga1m1cxvK/n5hi3MEj3x5NQVQlqbCldzLpExNUXDwJkjzgJ6m9K mXHgpzhV+EQ2NV6GbkMqmhNq5GKJg+KcjHqK4= Received: by 10.142.214.11 with SMTP id m11mr1390327wfg.69.1222556025307; Sat, 27 Sep 2008 15:53:45 -0700 (PDT) Received: by 10.142.171.15 with HTTP; Sat, 27 Sep 2008 15:53:45 -0700 (PDT) Message-ID: Date: Sun, 28 Sep 2008 00:53:45 +0200 From: "=?UTF-8?Q?Mikkel_Fahn=C3=B8e_J=C3=B8rgensen?=" Sender: mikkelfj@gmail.com To: "Joel Reymont" Subject: Re: [Caml-list] embedding ocaml into a windows app: need gcc? Cc: "O'Caml Mailing List" In-Reply-To: <1253374D-FC84-4394-99E5-46C02D26C54C@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <1253374D-FC84-4394-99E5-46C02D26C54C@gmail.com> X-Google-Sender-Auth: dd60fd06783cce7e X-Spam: no; 0.00; mikkel:01 rgensen:01 mikkel:01 ocaml:01 gcc:01 gcc:01 ocaml:01 compiler:01 compilation:01 compiler:01 ocamlopt:01 runtime:01 masm:01 masm:01 deploying:01 2008/9/27 Joel Reymont : > Can I do without gcc if I want to embed the OCaml compiler into a commercial > Windows app? I assume you mean native compilation. As mentioned, you should consider using a standalone ocaml compiler to avoid licensing issues, but either way: The ocamlopt compiler generates assembly source code and doesn't need a C compiler. It needs a runtime library, a linker and an assembler. On Windows you need to install masm - or find a compatible alternative. (On Unix I think gcc works as assembler). Masm can be downloaded without too much trouble - but if you start deploying it to other users, you may have a problem. Likewise, you must consider if your users have a linker installed and how you can distribute it legally. So assuming you have an assembler, ocaml compiler, linker and ocaml libraries: If you want to attach the generated code to a live process, you need to create a dll or a new process. If you want to attach to existing code then start a process, you can use static linking. So lets assume you want to create a dll. On Windows you don't need to compile position independent code, last time I looked, so -fPIC is not relevant. You compile an ocaml library and link it with other code as a dll. With the next ocaml version you might even be able to create a dll and use it not from OCaml but from any other program. Then the problem is solved - except for installing all the compile tools. Without the above solution, I have created such dll's some years back. More specifically to embed an ocamlyacc compiler in other Windows programs. You need to get the compile flags right, but it definitely is possible. You can also create a COM dll if you want - and call it from .Net. The benefit of a COM dll is that you get a clear calling interface and can interface with .NET easily. The downside is that COM projects are ugly. If you create a simple dll, you need a way to manage your call backs. I have an old ocamldll library for this purpose. It lets you register multiple ocaml function names in a dll and call them from the application by name. The new windows dll solution scheduled for next OCaml version has a more elegant solution where you don't have to register callbacks: http://alain.frisch.fr/natdynlink.html You can probably use this even with current OCaml version since it is Windows specific, not OCaml specific. Let me know if I should publish my ocamldll thing which will work, but is not cutting edge. All that being said: I have considered the same thing, and it is messy because of the compiler tools. I would like an OCaml support library that can compile and execute similar to JaveScript engines, but we don't have that in any practical form. So I would recommend looking into embedding a javascript compiler instead if performance is not absolutely critical - you could still drive fast ocaml library routines. In the past few months performance has exploded both in WebKit and Mozilla. Google has also released a fast engine named V8. WebKit has LGPL licensing issues, but Mozilla and V8 should be very embeddable. All compilers have JIT compilation, Mozilla also 64-bit. Or look at Haxe or Lua. Regards, Mikkel