caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] interfacing C++ with OCaml
@ 2002-07-04 17:21 Thierry SALSET
  2002-07-05  9:46 ` Xavier Leroy
  0 siblings, 1 reply; 3+ messages in thread
From: Thierry SALSET @ 2002-07-04 17:21 UTC (permalink / raw)
  To: caml-list

Hello list,

I used Camlidl to help me interface C functions and datatypes with OCaml
under Unix but now I would like to interface some existing (written by
others) C++ classes and methods with OCaml. I am not a C++ programmer
and I'm a little bit lost. Can Camlidl be of some help ? Should I write
a C layer between C++ and OCaml ?

Thanks in advance for your responses.


       Thierry Salset
       ENPC / CERMICS
       ts@cermics.enpc.fr
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Caml-list] interfacing C++ with OCaml
  2002-07-04 17:21 [Caml-list] interfacing C++ with OCaml Thierry SALSET
@ 2002-07-05  9:46 ` Xavier Leroy
  0 siblings, 0 replies; 3+ messages in thread
From: Xavier Leroy @ 2002-07-05  9:46 UTC (permalink / raw)
  To: Thierry SALSET; +Cc: caml-list

> I used Camlidl to help me interface C functions and datatypes with OCaml
> under Unix but now I would like to interface some existing (written by
> others) C++ classes and methods with OCaml. I am not a C++ programmer
> and I'm a little bit lost. Can Camlidl be of some help ? Should I write
> a C layer between C++ and OCaml ?

This is a reasonable option.  Once you have a pure C API for the
C++ code, you can use CamlIDL as usual.  

CamlIDL itself doesn't have any kind of direct support for C++.  Well,
it supports COM interfaces, which correspond to a very small subset of
C++ classes, but I doubt this can help you, unless the C++ code of
interest is already structured as COM interfaces.

The other alternative is to hand-write Caml wrappers that call
directly the C++ code, without going through C.  I believe you can
write those wrappers in C++ if you're careful to declare the entry points
(the functions that Caml will call) "extern "C"".

Some of the features of C++ might be used to wrap the Caml runtime API (the
functions and macros provided by <caml/mlvalues.h>, etc) in a more
C++-friendly style, see e.g.
         http://caml.inria.fr/archives/199704/msg00029.html 

Bon courage...

- Xavier Leroy
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Caml-list] Interfacing C with Ocaml
@ 2004-07-15 13:31 Julius
  0 siblings, 0 replies; 3+ messages in thread
From: Julius @ 2004-07-15 13:31 UTC (permalink / raw)
  To: caml-list

Hello,

I'am using ocamlidl to build an interface from custom C header but I have some 
problems (sorry if they are trivial)...

First, the following opaque structure definition doesn't pass the compilation 
stage (dereferencing pointer to incomplete type) :
typedef struct foo toto;
I thought this appens because C compiler doesn't know the size of foo 
structure. I tryed to define my own ml2c and c2ml functions (avoiding the 
problem by using pointers toto*) but I don't see how i can convert C pointer 
to Caml value...

Second, I have to give an IDL description of this awful thing...
typedef int (*foo_fun)(void*, int, char**, char**);
... and I really don't see how to do that.

Is anyone can help me? Thanks a lot :)

Julien Blond

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2004-07-15 13:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-07-04 17:21 [Caml-list] interfacing C++ with OCaml Thierry SALSET
2002-07-05  9:46 ` Xavier Leroy
2004-07-15 13:31 [Caml-list] Interfacing C with Ocaml Julius

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).