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