caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Xavier Leroy <xleroy@pauillac.inria.fr>
To: christ@mdhost.cse.TEK.COM
Cc: caml-list@pauillac.inria.fr
Subject: Re: interface to C++
Date: Wed, 20 Sep 1995 12:10:00 +0200 (MET DST)	[thread overview]
Message-ID: <199509201010.MAA10850@pauillac.inria.fr> (raw)
In-Reply-To: <9509181753.AA11777@ostar.CSE.TEK.COM> from "christ@mdhost.cse.TEK.COM" at Sep 18, 95 10:53:14 am

> Please help me answer a question. Is the 'camlc -custom' link
> command able to work with C++ objects?

I can't provide definitive answers, as I'm not an expert in C++. It
seems that the key point is how your C/C++ compiler allows C++
functions to be called from C. You may want to check first the
compiler docs or hotline, or post a query on comp.compilers. I had a
look at the gcc/g++ documentation, and it doesn't say anything about
this, unfortunately.

The Caml Light runtime system is basically a big set of C functions
that is entered at main() and eventually calls the user-provided C
functions. If you can link that with your C++ code so that
initializers get called correctly, then main() is called, the only
remaining problem is to understand how the names of your C++ functions
appear from the C side (I understand most C++ compilers "mangle" names
by adding type information or whatever to the function name.) Then,
just put the mangled names in the Caml "value" declarations, and
everything should work fine. To get your C++ compiler to be called
instead of the standard C compiler for building the custom executable,
use
        camlc -cc <the C++ compiler> -custom ...

or just hack the camlc command itself, it's a shell script.

It may be needed to define main() in C++ that just calls
Caml's main(), suitably renamed. It will take some more hacking in
camlc and maybe in libcaml.a.

If your compiler has different, incompatible calling conventions for C
and C++, then maybe it provdes some kind of pragma or declaration
to declare an external C++ function in a C file. Then, camlc will have
to edit /tmp/camlprim.$$.c to insert the correct C++ declarations.

Let me know how it works.

- Xavier Leroy




  reply	other threads:[~1995-09-20 11:28 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1995-09-18 17:53 christ
1995-09-20 10:10 ` Xavier Leroy [this message]
1995-09-20 12:01   ` Stefan Monnier
1995-09-20 12:43     ` Jean-Marie Geffroy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=199509201010.MAA10850@pauillac.inria.fr \
    --to=xleroy@pauillac.inria.fr \
    --cc=caml-list@pauillac.inria.fr \
    --cc=christ@mdhost.cse.TEK.COM \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).