Version française
Home     About     Download     Resources     Contact us    
Browse thread
linking errors involving cpp files
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Robert Roessler <roessler@r...>
Subject: Re: [Caml-list] linking errors involving cpp files
Aaron Bohannon wrote:
> How do I link C++ code with OCaml?  Let's say I have a main program in
> C/C++ and a function I want to call in OCaml:
>
> ---- main.c / main.cpp ---
> #include<caml/mlvalues.h>
> #include<caml/memory.h>
> #include<caml/callback.h>
> int main (int argc, char ** argv) {
>    char * caml_argv[argc + 1];
>    int i;
>    for (i = 0; i<  argc + 1; i++) caml_argv[i] = argv[i];
>    caml_argv[argc] = NULL;
>    caml_main (caml_argv);
>    return 0;
> }
> --------
>...
> ---then I get this:
>
> Undefined symbols:

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).

Robert Roessler