caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Mark Shinwell" <mshinwell@janestreet.com>
To: Aaron Bohannon <bohannon@cis.upenn.edu>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] linking errors involving cpp files
Date: Tue, 15 Dec 2009 13:59:59 +0000	[thread overview]
Message-ID: <20091215135959.GM17061@janestreet.com> (raw)
In-Reply-To: <c413fcb70912150550q6d103c39s3431850964ddda39@mail.gmail.com>

On Tue, Dec 15, 2009 at 08:50:33AM -0500, Aaron Bohannon wrote:
> On Tue, Dec 15, 2009 at 1:59 AM, Robert Roessler <roessler@rftp.com> wrote:
> > Aaron Bohannon wrote:
> >>
> >> How do I link C++ code with OCaml?
> 
> > You might try (when mixing C++ and OCaml) wrapping the whole thing in an
> > 'extern "C" {...}' block (*including* the #includes and the entire main
> > function).
> 
> Thanks for the tip.  This does resolve the missing caml symbols (even
> when naming the file with a cpp extension).  However, my real program
> actually uses some C++ features.  I think I could convert it to a real
> C program, but I assumed there would be some other way.

I suspect it will work if only the #include directives pertaining to Caml
header files are marked as 'extern "C"'.  You just need to tell the compiler to
use the C linkage convention rather than the C++ name mangling convention for
the external Caml functions that your program (implicitly or explicitly) calls.
This is done at the function prototype site, not the call site.  Everything
else in the program should be unaffected.

Xavier, could the headers have the guards added?  (I only spot-checked one,
mlvalues.h, and that didn't appear to have it).

Mark


  reply	other threads:[~2009-12-15 14:00 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-12-15  5:09 Aaron Bohannon
2009-12-15  6:59 ` [Caml-list] " Robert Roessler
2009-12-15 13:50   ` Aaron Bohannon
2009-12-15 13:59     ` Mark Shinwell [this message]
2009-12-15 20:47       ` Aaron Bohannon
2009-12-15 14:50     ` Jan Kybic
2009-12-15 15:04       ` Basile STARYNKEVITCH

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=20091215135959.GM17061@janestreet.com \
    --to=mshinwell@janestreet.com \
    --cc=bohannon@cis.upenn.edu \
    --cc=caml-list@inria.fr \
    /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).