Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] Link with C++ code
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2001-11-21 (07:15)
From: Clemens Hintze <cle-ocaml@q...>
Subject: Re: [Caml-list] Link with C++ code
On Tue, Nov 20, 2001 at 11:41:49PM +0100, Christophe TROESTLER wrote:
> Hi all,

Hi you,

> I am trying to use some C++ code from OCaml.  I am completely
> inexperienced at this (and not knowing well C++ to make matters worse)
> but in view of that didn't seem
> so difficult.  I will likely have more questions later but I am
> already stuck at the beginning.  Indeed, the C++ code includes the
> file "stl_alloc.h" which contains (gnu version, line 451)

does this mean, *you* are including "stl_alloc.h" directly? This you
should not do. You should not include any "stl_XXX.h" file. If you did
not please forgive me.

What you can do depends a bit on the version of the compiler you use
right now. The closest-to-standard G++ should be the 3.x chain of GCC.
Here all symbols of the STL are located in namespace 'std'. If your
code do *not*

  using namespace std;

you should not have problems then. Only, your code has to write
std::whatever in front of every STL datatype you use.

Other versions of GCC are not that close to the standard. They will
simply obey and ignore the 'std' identifier the same time :-(

> What can I do ?

You could try to wrap the OCaml stuff into a namespace, propably.
Like this:

  namespace ocaml {
    extern "C" {
  #   include <caml/alloc.h>

  int main(int argc, char* argv[])
    m = ocaml::alloc(...);


PS: Perhaps the OCaml headers could take sorrow on their own to wrap
    appropiate if included by an C++ compiler? Like this:

    #ifdef __cplusplus
    namespace OCaml {                /* (1) */
    extern "C" {
    /* Normal header file contents goes here */

    #ifdef __cplusplus
    } /* end of extern "C" */
    } /* end of namespace OCaml */   /* (1) */

    Perhaps a bit more adaption would necessary if using lines (1)?  
Bug reports:  FAQ:
To unsubscribe, mail  Archives: