From: Aaron Bohannon <bohannon@cis.upenn.edu>
To: Mark Shinwell <mshinwell@janestreet.com>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] linking errors involving cpp files
Date: Tue, 15 Dec 2009 15:47:44 -0500 [thread overview]
Message-ID: <c413fcb70912151247y4f55ccecta5f0583a4813abb5@mail.gmail.com> (raw)
In-Reply-To: <20091215135959.GM17061@janestreet.com>
Yes, it seems you're right. I just need the "extern" annotation
around the includes.
extern "C" {
#include <caml/mlvalues.h>
#include <caml/memory.h>
#include <caml/callback.h>
}
Thanks to everyone for the helpful comments.
- Aaron
On Tue, Dec 15, 2009 at 8:59 AM, Mark Shinwell <mshinwell@janestreet.com> wrote:
> 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
>
next prev parent reply other threads:[~2009-12-15 20:47 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
2009-12-15 20:47 ` Aaron Bohannon [this message]
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=c413fcb70912151247y4f55ccecta5f0583a4813abb5@mail.gmail.com \
--to=bohannon@cis.upenn.edu \
--cc=caml-list@inria.fr \
--cc=mshinwell@janestreet.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