caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Link with C++ code
@ 2001-11-20 22:41 Christophe TROESTLER
  2001-11-21  7:12 ` Clemens Hintze
  0 siblings, 1 reply; 2+ messages in thread
From: Christophe TROESTLER @ 2001-11-20 22:41 UTC (permalink / raw)
  To: O'Caml Mailing List

Hi all,

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 http://caml.inria.fr/Hump/msg778-782 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)

typedef __default_alloc_template<__NODE_ALLOCATOR_THREADS, 0> alloc;

and so conflicts with the definition of "alloc" in
"/usr/include/caml/alloc.h".

What can I do ?

ChriS



---
P.S.  For those who wonder, this attempt arises from a need to do
symbolic computation on multi-variable polynomials (with symbolic
coefficients).  First I thought to implement this directly in Caml
but, when I saw http://www.ginac.de/ I realized it is more useful to
try to use it from OCaml since I will never have time to do 1/10th of
what they already accomplished...  BTW, if you know other good algebra
packages that fit my need, feel free to let me know...
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


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

* Re: [Caml-list] Link with C++ code
  2001-11-20 22:41 [Caml-list] Link with C++ code Christophe TROESTLER
@ 2001-11-21  7:12 ` Clemens Hintze
  0 siblings, 0 replies; 2+ messages in thread
From: Clemens Hintze @ 2001-11-21  7:12 UTC (permalink / raw)
  To: Christophe TROESTLER; +Cc: O'Caml Mailing List

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 http://caml.inria.fr/Hump/msg778-782 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(...);
    :
  }


HTH,
Clemens.

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" {
    #endif
    
    /* Normal header file contents goes here */

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

    Perhaps a bit more adaption would necessary if using lines (1)?  
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


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

end of thread, other threads:[~2001-11-21  7:15 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-11-20 22:41 [Caml-list] Link with C++ code Christophe TROESTLER
2001-11-21  7:12 ` Clemens Hintze

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