* [Caml-list] Interop C-OCaml
@ 2016-10-03 15:32 Victor Pereira
0 siblings, 0 replies; only message in thread
From: Victor Pereira @ 2016-10-03 15:32 UTC (permalink / raw)
To: caml-list
[-- Attachment #1: Type: text/plain, Size: 1463 bytes --]
Hello all!
I have some function written in OCaml that I need to call in a C program.
The OCaml function takes a string, performs some computation and also
outputs a string. Note that these types are not mandatory, just for testing purposes.
Therefore, I defined a C function like:
char * foo (char * inp) {
CAMLlocal1 (caml_inp) ;
caml_inp = caml_copy_string (inp);
value * func = caml_named_value (“foo") ;
if (func == NULL)
puts (“Unable to load OCaml function!") ;
return strdup(String_val(caml_callback(*func, oinp)));
}
I am able to correctly compile the file with:
ocamlc -c foo.c (according to the manual)
Next, I define the main.c file as:
extern char * foo(char * inp);
int main (int argc, char ** argv)
{
/* Initialize OCaml code */
caml_startup(argv);
/* Do some computation */
char * inp = “some string";
printf ("%s\n", foo(inp));
return 0;
}
However, I’m not able to compile the main.c file!
The error output is the following:
Undefined symbols for architecture x86_64:
"_caml_startup", referenced from:
_main in main-05d208.o
“_foo", referenced from:
_main in main-05d208.o
I followed the instructions in the manual to interop C and OCaml when
the main program is in the C side.
Nevertheless, If I run the example in the manual, it works very well!
Any idea on what am I doing wrong?
Best,
Vitor
[-- Attachment #2: Type: text/html, Size: 5667 bytes --]
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2016-10-03 15:32 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-10-03 15:32 [Caml-list] Interop C-OCaml Victor Pereira
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox