From: Michael Ekstrand <michael@elehack.net>
To: caml-list@inria.fr
Subject: Re: How to call OCaml from C++
Date: Tue, 23 Feb 2010 19:11:11 -0600 [thread overview]
Message-ID: <hm1ubf$iu9$1@dough.gmane.org> (raw)
In-Reply-To: <9dfe358d1002221911x27e70e1h7c1521b38184e372@mail.gmail.com>
On 02/22/2010 09:11 PM, Jianzhou Zhao wrote:
> Hi,
>
> Does anyone call OCaml code from C++?
> C can call OCaml with the OCaml foreign interfaces.
> But when we call OCaml from C++, we need to consider ‘extern C'
> stuff, like what we do when call C from C++, because the bridge
> functions between C and OCaml are written in C.
>
> However, those functions have not been prefixed with 'extern C',
> and some functions, such as caml_alloc_dummy in libasmrun, have not
> been exposed
> in a head file. So it is hard to define a wrapper to let it work in C++.
> When linking C++ and libasmrun, caml_alloc_dummy cannot
> be found by the linker.
If you include your OCaml includes in an 'extern C' block like this:
extern "C" {
#include <caml/mlvalues.h>
/* other OCaml includes */
}
then the C++ compiler should have the right symbol names so that it can
look things up in the runtime. The headers do not have extern C
declarations in them, but they are able to be imported cleanly in an
extern "C" block.
- Michael
prev parent reply other threads:[~2010-02-24 1:11 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-02-23 3:11 Jianzhou Zhao
2010-02-24 1:11 ` Michael Ekstrand [this message]
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='hm1ubf$iu9$1@dough.gmane.org' \
--to=michael@elehack.net \
--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).