Re: Calling C++ from Caml

From: John Prevost (prevost@maya.com)
Date: Mon Apr 17 2000 - 21:25:36 MET DST

  • Next message: John Prevost: "Re: When functional languages can be accepted by industry?"

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



    This archive was generated by hypermail 2b29 : Wed Apr 19 2000 - 14:12:33 MET DST