* Calling C++ from Caml
@ 2000-04-16 13:40 Ohad Rodeh
2000-04-17 19:25 ` John Prevost
0 siblings, 1 reply; 2+ messages in thread
From: Ohad Rodeh @ 2000-04-16 13:40 UTC (permalink / raw)
To: caml-list
Hello,
I'm trying to use C++ code from within Caml. Currently,
the compiler cannot find the requested functions in the compiled
C++ code.
A very simple example fails. I have two files:
dh.ml : ML code
xx.cpp : C++ code
The C++ code contains the function:
value dhml_Try(value dummy) {
return Val_unit;
}
The ML code calls dhml_Try using:
external dhml_Try : unit -> unit
= "dhml_Try"
let _ =
dhml_Try();
()
The compilation seqeunce is as follows:
c++ -c -w -I$(CAMLLIB) xx.cpp -o xx.o
ocamlc -c dh.ml
ocamlc -cc c++ -custom -o dh xx.o dh.cmo
/tmp/ccEPQ4W1.o(.data+0x248): undefined reference to `dhml_Try'
If I use the gcc compiler with C code, instead of C++, this
sequence works fine. How can I fix this problem?
Thanks,
Ohad.
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Calling C++ from Caml
2000-04-16 13:40 Calling C++ from Caml Ohad Rodeh
@ 2000-04-17 19:25 ` John Prevost
0 siblings, 0 replies; 2+ messages in thread
From: John Prevost @ 2000-04-17 19:25 UTC (permalink / raw)
To: Ohad Rodeh; +Cc: caml-list
>>>>> "or" == Ohad Rodeh <orodeh@cs.huji.ac.il> writes:
or> Hello, I'm trying to use C++ code from within Caml. Currently,
or> the compiler cannot find the requested functions in the
or> compiled C++ code.
{...}
or> If I use the gcc compiler with C code, instead of C++, this
or> sequence works fine. How can I fix this problem?
C++ compilers need to do "name-mangling" in order to support
overloading functions. This adds information about the types of the
arguments to the function's name, and makes it hard for O'Caml to
find.
I suspect that using the following prototype would work for you:
extern "C" {
value dhml_Try(value dummy);
}
the `extern "C"' part requests that the following be done with C
calling conventions. I'm not up on my C++, so this may be
insufficient when you're defining the function in the current
file--you may need to use the extern declaration around the function's
definition.
John.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2000-04-19 12:00 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-04-16 13:40 Calling C++ from Caml Ohad Rodeh
2000-04-17 19:25 ` John Prevost
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox