Version française
Home     About     Download     Resources     Contact us    
Browse thread
How to wrap around C++?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Luca de Alfaro <luca@d...>
Subject: Re: [Caml-list] Re: How to wrap around C++?
Thank you very much!  I follow the general lines, but...


> * Make sure no C++ exceptions leak to OCaml.
>

This will be next to impossible: the C++ code I need to wrap is huge, and I
have no idea of what possible exceptions can be generated.  I will have to
try to see if there is a generic exception catcher.


> * Wrap your OCaml includes in 'extern "C" { ... }"
>

Here, I am not sure what you mean.  You mean,

extern "C" {
#include <caml/mlvalues.h>
...
}

?


> * Export all your stub functions with C linkage (extern "C")
>

Ok, evidently, I need to learn this extern "C" construct.


> * Compiling is tricky, since the OCaml compiler driver doesn't know what
> to do with C++.  The Swig documentation[1] has a workaround for this,
> useful even if you don't use Swig.
>
>
Why would the Ocaml compiler driver need to know what to do with C++?
The C++ I need to link to is rather huge, and I will need to compile it with
its own build setup.
Once that is built, I need to compile the stubs, the Ocaml, and link the
three together (Ocaml, stubs, and C++), in native mode, but  why would the
Ocaml compiler need to deal with C++?

Another question: I could also try to do the vice-versa, and use Ocaml as
libraries from C++.  Has anybody tried doing this?  Is it easy to do?

Luca