caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* interface to C++
@ 1995-09-18 17:53 christ
  1995-09-20 10:10 ` Xavier Leroy
  0 siblings, 1 reply; 4+ messages in thread
From: christ @ 1995-09-18 17:53 UTC (permalink / raw)
  To: caml-list

Hi.

Please help me answer a question. Is the 'camlc -custom' link
command able to work with C++ objects? I would guess it is not,
but would appreciate any ideas for linking with C++. The startup
code would have to run the extra initializer functions, so it's
mostly a factor of what compiler is used I think. Again, thank
you for any help.

Thanks, Chris

P.S. Thanks for making caml available. It's a great alternative
to SMLNJ. Nice job.

Chris Tilt				    chris.tilt@tek.com
Tektronix, Inc.				Beaverton, Oregon, USA





^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: interface to C++
  1995-09-18 17:53 interface to C++ christ
@ 1995-09-20 10:10 ` Xavier Leroy
  1995-09-20 12:01   ` Stefan Monnier
  0 siblings, 1 reply; 4+ messages in thread
From: Xavier Leroy @ 1995-09-20 10:10 UTC (permalink / raw)
  To: christ; +Cc: caml-list

> Please help me answer a question. Is the 'camlc -custom' link
> command able to work with C++ objects?

I can't provide definitive answers, as I'm not an expert in C++. It
seems that the key point is how your C/C++ compiler allows C++
functions to be called from C. You may want to check first the
compiler docs or hotline, or post a query on comp.compilers. I had a
look at the gcc/g++ documentation, and it doesn't say anything about
this, unfortunately.

The Caml Light runtime system is basically a big set of C functions
that is entered at main() and eventually calls the user-provided C
functions. If you can link that with your C++ code so that
initializers get called correctly, then main() is called, the only
remaining problem is to understand how the names of your C++ functions
appear from the C side (I understand most C++ compilers "mangle" names
by adding type information or whatever to the function name.) Then,
just put the mangled names in the Caml "value" declarations, and
everything should work fine. To get your C++ compiler to be called
instead of the standard C compiler for building the custom executable,
use
        camlc -cc <the C++ compiler> -custom ...

or just hack the camlc command itself, it's a shell script.

It may be needed to define main() in C++ that just calls
Caml's main(), suitably renamed. It will take some more hacking in
camlc and maybe in libcaml.a.

If your compiler has different, incompatible calling conventions for C
and C++, then maybe it provdes some kind of pragma or declaration
to declare an external C++ function in a C file. Then, camlc will have
to edit /tmp/camlprim.$$.c to insert the correct C++ declarations.

Let me know how it works.

- Xavier Leroy




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: interface to C++
  1995-09-20 10:10 ` Xavier Leroy
@ 1995-09-20 12:01   ` Stefan Monnier
  1995-09-20 12:43     ` Jean-Marie Geffroy
  0 siblings, 1 reply; 4+ messages in thread
From: Stefan Monnier @ 1995-09-20 12:01 UTC (permalink / raw)
  To: christ; +Cc: caml-list

Xavier Leroy <Xavier.Leroy@inria.fr> wrote:
> by adding type information or whatever to the function name.) Then,
> just put the mangled names in the Caml "value" declarations, and
> everything should work fine. To get your C++ compiler to be called

Rather than mess around with the mangled names, you might be better off trying
to compile caml-light with your C++ compiler so that the name (de)mangling
is all done by your compiler. Since C++ is an approximate superset of ANSI C,
it might work.
(but don't ask me how to interface caml-light with C++ objects and methods.
I have no idea how easy it can be to add custom-made types)


	Stefan






^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: interface to C++
  1995-09-20 12:01   ` Stefan Monnier
@ 1995-09-20 12:43     ` Jean-Marie Geffroy
  0 siblings, 0 replies; 4+ messages in thread
From: Jean-Marie Geffroy @ 1995-09-20 12:43 UTC (permalink / raw)
  To: stefan.monnier; +Cc: christ, caml-list


Stefan Monnier <stefan.monnier@epfl.ch> wrote

> Rather than mess around with the mangled names, you might be better
> off trying to compile caml-light with your C++ compiler so that the
> name (de)mangling is all done by your compiler. Since C++ is an
> approximate superset of ANSI C, it might work.

Right. The Windows version (1) is in fact already compiled this way:
the standard caml system is written in pure C but compiled with a C++
compiler. The graphical interface is written in C++ and uses the
MFC. It exports 5 or 6 functions through extern "C" declarations such
as:

extern "C" ui_xxx(...){...}

The C modules contain standard extern declarations:

extern ui_xxx(...);

Linking C++ functions is thus completely straightforward and there's no
messing around with names.

Hope this helps !

    Jean-Marie


(1) soon available !




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~1995-09-20 12:54 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1995-09-18 17:53 interface to C++ christ
1995-09-20 10:10 ` Xavier Leroy
1995-09-20 12:01   ` Stefan Monnier
1995-09-20 12:43     ` Jean-Marie Geffroy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).