2008/9/27 Joel Reymont <[EMAIL PROTECTED]>:
> 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

_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs

Reply via email to