caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Interfacing C++ and Ocaml
@ 2001-03-30  8:54 David Chemouil
  2001-03-30  9:13 ` Bruce Hoult
  2001-03-30 16:50 ` Overloading again (Was Re: [Caml-list] Interfacing C++ and Ocaml) Brian Rogoff
  0 siblings, 2 replies; 18+ messages in thread
From: David Chemouil @ 2001-03-30  8:54 UTC (permalink / raw)
  To: caml-list


Hi,



I am in the situation where I would like to write an Ocaml program which
makes use of some C++ classes. It seems to me some people had said there
were some problems doing so, but I can't recall what these problems may
be, and didn't find anything precise in the ML archive.

So, I would like to know what may prevent me to reuse C++ code from
Ocaml, if anything may. I am sure some arrangements can be done, as
there exists an Ocaml implementation on BeOS, which is programmed in
C++. 

Moreover, if it is possible, what do you advise me to do? What are the
limitations? Have you got simple examples of such interfacings?


Thanks in advance,

dc



PS: BTW, I would like to thank these happy volunteers who aim at
packaging a Caml Development Kit. IMO, this is truly a good idea, which
may help Caml spread. Just a question to the Caml team: I would like to
know if (when?) you intend to include polymorphic I/O and some kind of
overloading in a forthcoming release of Caml. It seems to me Pierre had
written some mails about this, but is is now a long time ago, how is the
situation today?


-- 
David Chemouil    [mailto:David.Chemouil@irit.fr]

Institut de recherche en informatique de Toulouse
-------------------
To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr


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

* Re: [Caml-list] Interfacing C++ and Ocaml
  2001-03-30  8:54 [Caml-list] Interfacing C++ and Ocaml David Chemouil
@ 2001-03-30  9:13 ` Bruce Hoult
  2001-03-30  9:24   ` Fergus Henderson
  2001-03-30 16:50 ` Overloading again (Was Re: [Caml-list] Interfacing C++ and Ocaml) Brian Rogoff
  1 sibling, 1 reply; 18+ messages in thread
From: Bruce Hoult @ 2001-03-30  9:13 UTC (permalink / raw)
  To: David Chemouil, caml-list

At 10:54 AM +0200 3/30/01, David Chemouil wrote:
>Hi,
>
>
>
>I am in the situation where I would like to write an Ocaml program which
>makes use of some C++ classes. It seems to me some people had said there
>were some problems doing so, but I can't recall what these problems may
>be, and didn't find anything precise in the ML archive.
>
>So, I would like to know what may prevent me to reuse C++ code from
>Ocaml, if anything may. I am sure some arrangements can be done, as
>there exists an Ocaml implementation on BeOS, which is programmed in
>C++.

I'm no expert on Caml, so maybe the wizards have done something 
clever, but interfacing other languages to C++ is normally best done 
by writing an adaptor in C++ that provides a pure C interface to the 
C++ code (usable by C code, compiled by a C compiler, not C++), and 
then call *that* from your favourite language.

-- Bruce
-------------------
To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr


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

* Re: [Caml-list] Interfacing C++ and Ocaml
  2001-03-30  9:13 ` Bruce Hoult
@ 2001-03-30  9:24   ` Fergus Henderson
  0 siblings, 0 replies; 18+ messages in thread
From: Fergus Henderson @ 2001-03-30  9:24 UTC (permalink / raw)
  To: Bruce Hoult; +Cc: David Chemouil, caml-list

On 30-Mar-2001, Bruce Hoult <bruce@hoult.org> wrote:
> I'm no expert on Caml, so maybe the wizards have done something 
> clever, but interfacing other languages to C++ is normally best done 
> by writing an adaptor in C++ that provides a pure C interface to the 
> C++ code (usable by C code, compiled by a C compiler, not C++), and 

In particular defining the C++ functions in your adaptor code
as `extern "C"' so that they can be called from C code.

-- 
Fergus Henderson <fjh@cs.mu.oz.au>  |  "I have always known that the pursuit
                                    |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.
-------------------
To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr


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

* Overloading again (Was Re: [Caml-list] Interfacing C++ and Ocaml)
  2001-03-30  8:54 [Caml-list] Interfacing C++ and Ocaml David Chemouil
  2001-03-30  9:13 ` Bruce Hoult
@ 2001-03-30 16:50 ` Brian Rogoff
  2001-04-02  8:13   ` Jean-Marc Alliot
  1 sibling, 1 reply; 18+ messages in thread
From: Brian Rogoff @ 2001-03-30 16:50 UTC (permalink / raw)
  To: David Chemouil; +Cc: caml-list

On Fri, 30 Mar 2001, David Chemouil wrote:
> PS: BTW, I would like to thank these happy volunteers who aim at
> packaging a Caml Development Kit. IMO, this is truly a good idea, which
> may help Caml spread. Just a question to the Caml team: I would like to
> know if (when?) you intend to include polymorphic I/O and some kind of
> overloading in a forthcoming release of Caml. It seems to me Pierre had
> written some mails about this, but is is now a long time ago, how is the
> situation today?

An even longer time ago I asked about overloading and got a nice long
reply from Francois Rouaix, describing the history of overloading in Caml
and ending with something like "Jun Furuse is now working on it". You can
read about the latest incarnation of his work by going to 

http://pauillac.inria.fr/jfla/2001/actes/index.html

and downloading 

Generic Polymorphism in ML

which as you can guess is in English unlike his paper last year. 

I'd also love to know if and when this will make it into Ocaml since this
is one of the few things that I dislike about ML style languages and
even after quite a bit of Caml programming I still miss overloading. 

-- Brian


-------------------
To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr


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

* Re: Overloading again (Was Re: [Caml-list] Interfacing C++ and Ocaml)
  2001-03-30 16:50 ` Overloading again (Was Re: [Caml-list] Interfacing C++ and Ocaml) Brian Rogoff
@ 2001-04-02  8:13   ` Jean-Marc Alliot
  2001-04-02 13:48     ` Fergus Henderson
  2001-04-02 15:51     ` Brock
  0 siblings, 2 replies; 18+ messages in thread
From: Jean-Marc Alliot @ 2001-04-02  8:13 UTC (permalink / raw)
  Cc: caml-list

Brian Rogoff wrote:

> I'd also love to know if and when this will make it into Ocaml since this
> is one of the few things that I dislike about ML style languages and
> even after quite a bit of Caml programming I still miss overloading.
>

Well, I am going to be the black sheep again, but as an old ADA and C++ programmer,
I don't really want to see overloading pop up in ML.

Overloading can become easily a source of mistakes. My favorite example is the
following. A few years ago, I was managing a project with C++ code, and one of the
programmer was using a third party library (the author of this library was gone and
had been replaced). And he had a bug inside the following code fragment in that
library:

toto(titi *initp)
{
titi *p;

for (p=initp;p!=NULL;p++)
   {
     .......
   }

}

And it took him a very long time to realize that the ++ operator had been
overloaded, somewhere in a .h file included in an other .h file, and that instead
of incrmenting the pointer, it was doing something like p=p->next, with a next
field incorrectly initialized somewhere.

Having different names for different functions is, according to me, an excellent
thing.

JMA


-------------------
To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr


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

* Re: Overloading again (Was Re: [Caml-list] Interfacing C++ and Ocaml)
  2001-04-02  8:13   ` Jean-Marc Alliot
@ 2001-04-02 13:48     ` Fergus Henderson
  2001-04-02 14:30       ` Jean-Marc Alliot
  2001-04-02 15:51     ` Brock
  1 sibling, 1 reply; 18+ messages in thread
From: Fergus Henderson @ 2001-04-02 13:48 UTC (permalink / raw)
  To: Jean-Marc Alliot; +Cc: caml-list

On 02-Apr-2001, Jean-Marc Alliot <alliot@recherche.enac.fr> wrote:
> Well, I am going to be the black sheep again, but as an old ADA and C++
> programmer, I don't really want to see overloading pop up in ML.

Incidentally, it's "Ada", not "ADA".

> Overloading can become easily a source of mistakes. My favorite example
> is the following. A few years ago, I was managing a project with C++
> code, and one of the programmer was using a third party library (the
> author of this library was gone and had been replaced). And he had a
> bug inside the following code fragment in that library:
>
> toto(titi *initp)
> {
> titi *p;
> 
> for (p=initp;p!=NULL;p++)
>    {
>      .......
>    }
> 
> }
> 
> And it took him a very long time to realize that the ++ operator had
> been overloaded, somewhere in a .h file included in an other .h file,
> and that instead of incrmenting the pointer, it was doing something
> like p=p->next, with a next field incorrectly initialized somewhere.

This example is a bogus example, since C++ doesn't allow that kind of
overloading.  C++ requires that every overloaded operator have at least
one parameter whose type is a class, or a reference to a class,
an enumeration, or a reference to an enumeration (see e.g. 13.1.1.2
in the C++ standard).  In this case the argument has pointer type,
so it can't call an overloaded operator.

My opinion with regard to overloading is that what is really
problematic about overloading in C++ is the *combination* of
overloading and implicit conversions.

Mercury supports overloading, without implicit conversions,
in my experience it works fine.  The main drawbacks are that
(a) occaisionally you need to use explicit type annotations
to resolve ambiguities and (b) sometimes the presence of overloading
makes it harder for the type checker to issue good error messages.

-- 
Fergus Henderson <fjh@cs.mu.oz.au>  |  "I have always known that the pursuit
                                    |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.
-------------------
To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr


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

* Re: Overloading again (Was Re: [Caml-list] Interfacing C++ and Ocaml)
  2001-04-02 13:48     ` Fergus Henderson
@ 2001-04-02 14:30       ` Jean-Marc Alliot
  2001-04-02 15:49         ` Brian Rogoff
  0 siblings, 1 reply; 18+ messages in thread
From: Jean-Marc Alliot @ 2001-04-02 14:30 UTC (permalink / raw)
  To: Fergus Henderson; +Cc: caml-list

Fergus Henderson wrote:

> This example is a bogus example, since C++ doesn't allow that kind of
> overloading.  C++ requires that every overloaded operator have at least
> one parameter whose type is a class, or a reference to a class,
> an enumeration, or a reference to an enumeration (see e.g. 13.1.1.2
> in the C++ standard).  In this case the argument has pointer type,
> so it can't call an overloaded operator.
>

Right, it was back from a fragment of my memory. The example was slightly more
complex, but took as much time to be debugged.

>
> My opinion with regard to overloading is that what is really
> problematic about overloading in C++ is the *combination* of
> overloading and implicit conversions.

Yes (in C++ it is much more horrible because of implicit conversions) and no : it
is also bad in language like Ada (yes not ADA, right again, sorry lady Lovelace).
It is in fact forbidden to use overloading by many quality manuals, (and so is the
USE directive for example).  I hated that quality manual in the beginning, I now
consider that it is not as terrible as I thought when I was younger. From your
mail, I would say you're younger than I am... :-)


--
|             Jean-Marc Alliot          |
|  http://www.recherche.enac.fr/~alliot |
|         alliot@recherche.enac.fr      |



-------------------
To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr


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

* Re: Overloading again (Was Re: [Caml-list] Interfacing C++ and Ocaml)
  2001-04-02 14:30       ` Jean-Marc Alliot
@ 2001-04-02 15:49         ` Brian Rogoff
  2001-04-09  6:47           ` John Max Skaller
  0 siblings, 1 reply; 18+ messages in thread
From: Brian Rogoff @ 2001-04-02 15:49 UTC (permalink / raw)
  To: Jean-Marc Alliot; +Cc: Fergus Henderson, caml-list

On Mon, 2 Apr 2001, Jean-Marc Alliot wrote:
> Fergus Henderson wrote:
> > My opinion with regard to overloading is that what is really
> > problematic about overloading in C++ is the *combination* of
> > overloading and implicit conversions.

I agree with Fergus on this. Clearly one can make a mess with overloading, 
but used with good taste it really makes programs better. I've always
found it interesting that fans of type inference tell us how great it is
not to be burdened with writing out explicit type information (which many 
programmers would consider helpful documentation) only to be left sticking
it onto function names. Labels help us a bit here (thanks Jacques!) but 
a little bit of overloading really helps.  

In C++, well, .... I agree that the combination of implicit conversions
and overloading is a disaster. 

> It is in fact forbidden to use overloading by many quality manuals,

Well, Jean Ichbiah and his Green team put it in so I imagine they thought
it could be used to write more maintainable code. Anyways, the AQS doesn't 
ban overloading but states the obvious

     Limit overloading to widely used subprograms that perform similar
     actions on arguments of different types (Nissen and Wallis 1984). 

and other obvious rules of thumb. 

> (and so is the USE directive for example). 

See "In Defense of the Use Clause" by Jean-Pierre Rosen at 

    http://perso.wanadoo.fr/adalog/publica2.htm

> I hated that quality manual in the beginning, I now
> consider that it is not as terrible as I thought when I was
> younger. From your  mail, I would say you're younger than I am... :-)

That's really not an appropriate way to argue, now is it? 

-- Brian


-------------------
To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr


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

* Re: Overloading again (Was Re: [Caml-list] Interfacing C++ and Ocaml)
  2001-04-02  8:13   ` Jean-Marc Alliot
  2001-04-02 13:48     ` Fergus Henderson
@ 2001-04-02 15:51     ` Brock
  1 sibling, 0 replies; 18+ messages in thread
From: Brock @ 2001-04-02 15:51 UTC (permalink / raw)
  To: Jean-Marc Alliot; +Cc: caml-list


On Mon, 2 Apr 2001, Jean-Marc Alliot wrote:

|Brian Rogoff wrote:
|
|> I'd also love to know if and when this will make it into Ocaml since this
|> is one of the few things that I dislike about ML style languages and
|> even after quite a bit of Caml programming I still miss overloading.
|>
...
|
|And it took him a very long time to realize that the ++ operator had been
|overloaded, somewhere in a .h file included in an other .h file, and that instead
|of incrmenting the pointer, it was doing something like p=p->next, with a next
|field incorrectly initialized somewhere.
|

Wouldn't our lovely typechecking system take care of this?

--Brock
-------------------
To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr


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

* Re: Overloading again (Was Re: [Caml-list] Interfacing C++ and Ocaml)
  2001-04-02 15:49         ` Brian Rogoff
@ 2001-04-09  6:47           ` John Max Skaller
  0 siblings, 0 replies; 18+ messages in thread
From: John Max Skaller @ 2001-04-09  6:47 UTC (permalink / raw)
  To: Brian Rogoff; +Cc: Jean-Marc Alliot, Fergus Henderson, caml-list

Brian Rogoff wrote:
> 
> On Mon, 2 Apr 2001, Jean-Marc Alliot wrote:
> > Fergus Henderson wrote:
> > > My opinion with regard to overloading is that what is really
> > > problematic about overloading in C++ is the *combination* of
> > > overloading and implicit conversions.
> 
> I agree with Fergus on this. 

	This is not just a matter of opinion but mathematics.
There is a paper dealing with the interaction of generics
and implicit conversions which details conditions under which
both can coexist without ambiguity:

	Using Category Theory to Design Implicit Conversions
	and Generic Operators, John C  Reynolds, 
	Theoretical Aspects of Object-Oriented Programming,
	Gunter and Mitchell, MIT Press ISBN 0-262-07155-X


-- 
John (Max) Skaller, mailto:skaller@maxtal.com.au
10/1 Toxteth Rd Glebe NSW 2037 Australia voice: 61-2-9660-0850
checkout Vyper http://Vyper.sourceforge.net
download Interscript http://Interscript.sourceforge.net
-------------------
To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr


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

* Re: [Caml-list] interfacing C and OCaml
  2003-06-27  5:24   ` Re[2]: " Mikhail Fedotov
@ 2003-06-27  8:31     ` Jean-Baptiste Rouquier
  0 siblings, 0 replies; 18+ messages in thread
From: Jean-Baptiste Rouquier @ 2003-06-27  8:31 UTC (permalink / raw)
  To: caml-list

> JBR> 1. Should I use
> JBR> CAMLprim value input(value channel, value buffer, value offset, value
> JBR> length)
> JBR> {
> JBR>   return Val_long (...);
> JBR> }
>
> Yes. This function can be called from other C function or from OCaml.
>
> JBR> as in 18.1.2 in the manual, or
>
> JBR> void foo (value v1, value v2, value v3)
> JBR> {
> JBR> CAMLparam3 (v1, v2, v3);
> JBR> ...
> JBR> CAMLreturn0;
> JBR> }
>
> This if for functions called from C only. Not suitable for use from
> OCaml directly.
>
> Should be specified in the manual, I believe, but I've got no response
> in the list to my comment on this. I hope it will be in the manual for
> the OCaml 3.07.
>


Strange !
The complete example given in 18.6 contains :

curses.mli :
external initscr: unit -> window = "curses_initscr"

curses.c ("curses.o" in the manual) :
value curses_initscr(value unit)
{
CAMLparam1 (unit);
CAMLreturn ((value) initscr());
}

curses.ml :
open Curses
let main_window = initscr () in


So functions using CAMLparam and CAMLreturn are called from OCaml directly.
Or am I completely wrong ?
I'm worried about the GC (for now, my code seems to run correctly, but use
perhaps to much memory).


Thanks,
JBR

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


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

* Re: [Caml-list] interfacing C and OCaml
  2003-06-26 14:42 [Caml-list] interfacing C and OCaml Jung Woon Ho
  2003-06-26 15:14 ` Lex Stein
@ 2003-06-26 19:02 ` Jean-Baptiste Rouquier
  2003-06-27  5:24   ` Re[2]: " Mikhail Fedotov
  1 sibling, 1 reply; 18+ messages in thread
From: Jean-Baptiste Rouquier @ 2003-06-26 19:02 UTC (permalink / raw)
  To: caml-list

> Can anybody explain me if there is anyway that I can pass in
> a (int*int*int*int*int) from a C function to OCaml.

Do you want to call C auxiliary function from Caml, or are you writing your
main programm in C and using some Caml functions ?
Both are very well explained in the manual, though it may take a while to
read it.
Don't hesitate to ask me for a complete example if your main programm is in
Caml (I haven't learn yet how to write the main programm in C).



------------------------------------------------
À propos, I have some questions about the manual :
1. Should I use
CAMLprim value input(value channel, value buffer, value offset, value
length)
{
  return ...
}

as in 18.1.2 in the manual, or

void foo (value v1, value v2, value v3)
{
CAMLparam3 (v1, v2, v3);
...
CAMLreturn0;
}

as in 18.5.1, or both ? I think at least the second.


------------------------------------------------
2.
I use
  alloc(2*n, Double_array_tag.)
to create a float array of size n (then I initialize it), is it correct ?


------------------------------------------------
3. Is it correct to store p in the custom block v by
CAMLlocal(v);
v = alloc_custom(ops, 4, 0, 1);
(my_type *) Data_custom_val(v) = p;
?
When does the parameter "size" (here "4") vary ?

Thanks,
Jean-Baptiste.








-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


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

* Re: [Caml-list] interfacing C and OCaml
  2003-06-26 14:42 [Caml-list] interfacing C and OCaml Jung Woon Ho
@ 2003-06-26 15:14 ` Lex Stein
  2003-06-26 19:02 ` Jean-Baptiste Rouquier
  1 sibling, 0 replies; 18+ messages in thread
From: Lex Stein @ 2003-06-26 15:14 UTC (permalink / raw)
  To: Jung Woon Ho; +Cc: caml-list


Hi, In the C code allocate a memory block value of size 5 with tag 0.

CAMLparam0 ();
CAMLlocal2 (v, v1);
static value * clos;

v = alloc_tuple (5);
/* assign to the fields using the Store_Field macro */

clos = caml_named_value ("c_function_name")

/* where c_function_name is registered from within the Caml code
   via (Callback.register "c_function_name" function_name)
Then just call the Caml routine via callback like so: */

v1 = callback (*clos, v);

Remember to return from the C function with one of the CAMLreturn
macros to be friendly with the garbage collector.

Let me know if you have any further questions/problems with Caml/C
interaction. I'm happy to help.

Lex

--
Lex Stein                     http://www.eecs.harvard.edu/~stein/
stein@eecs.harvard.edu        TEL: 617-233-0246


On Thu, 26 Jun 2003, Jung Woon Ho wrote:

> Hi,
>
> Can anybody explain me if there is anyway that I can pass in
> a (int*int*int*int*int) from a C function to OCaml.
>
> Thank you.
>
> _________________________________________________________________
> The new MSN 8: smart spam protection and 2 months FREE*
> http://join.msn.com/?page=features/junkmail
>
> -------------------
> To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
> Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
>

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


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

* [Caml-list] interfacing C and OCaml
@ 2003-06-26 14:42 Jung Woon Ho
  2003-06-26 15:14 ` Lex Stein
  2003-06-26 19:02 ` Jean-Baptiste Rouquier
  0 siblings, 2 replies; 18+ messages in thread
From: Jung Woon Ho @ 2003-06-26 14:42 UTC (permalink / raw)
  To: caml-list

Hi,

Can anybody explain me if there is anyway that I can pass in
a (int*int*int*int*int) from a C function to OCaml.

Thank you.

_________________________________________________________________
The new MSN 8: smart spam protection and 2 months FREE*  
http://join.msn.com/?page=features/junkmail

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


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

* Re: [Caml-list] Interfacing C and Ocaml
  2003-06-19 19:58 [Caml-list] Interfacing C and Ocaml Jung Woon Ho
  2003-06-19 20:06 ` Kip Macy
@ 2003-06-19 20:28 ` art yerkes
  1 sibling, 0 replies; 18+ messages in thread
From: art yerkes @ 2003-06-19 20:28 UTC (permalink / raw)
  To: Jung Woon Ho; +Cc: caml-list, unosoft

On Thu, 19 Jun 2003 19:58:16 +0000
"Jung Woon Ho" <unosoft@hotmail.com> wrote:

See: http://lists.suse.com/archive/suse-linux-e/2001-Aug/0476.html

It appears that the name of the curses library on Suse is libncurses.

> Hi, Im trying to implement a simple program that interfaces C and Ocaml.
> Here is what I do:
> 
>         ocamlc -custom -output-obj -o modcaml.o mod.ml
>         ocamlc -c modwrap.c
>         cp /usr/local/lib/ocaml/libcamlrun.a mod.a
>         ar r mod.a modcaml.o modwrap.o
> 	cc -o prog main.c mod.a -lcurses
> 
> and I get the error:
> /usr/lib/gcc-lib/i486-suse-linux/3.2/../../../../i486-suse-linux/bin/ld: 
> cannot find -lcurses
> collect2: ld returned 1 exit status
> 
> I tried cc -o prog main.c mod.a -lcurses -ltermcap and cc -o prog main.c 
> mod.a -ltermcap but i cant get the program to link.
> 
> Does anybody know how to solve this problem?
> 
> Thank you very much.
> 
> 
> 
> 
> ---------------------mod.ml-------------------------------
> (* File mod.ml -- some ``useful'' Caml functions *)
> 
> let rec fib n = if n < 2 then 1 else fib(n-1) + fib(n-2)
> 
> let format_result n = Printf.sprintf "Result is: %d\n" n
> 
> (* Export those two functions to C *)
> 
> let _ = Callback.register "fib" fib
> let _ = Callback.register "format_result" format_result
> ----------------------------------------------------------
> 
> --------------------modwrap.c-----------------------------
> /* File modwrap.c -- wrappers around the Caml functions */
> 
> #include <stdio.h>
> #include <string.h>
> #include <caml/mlvalues.h>
> #include <caml/callback.h>
> 
> int fib(int n)
> {
>   static value * fib_closure = NULL;
>   if (fib_closure == NULL) fib_closure = caml_named_value("fib");
>   return Int_val(callback(*fib_closure, Val_int(n)));
> }
> 
> char * format_result(int n)
> {
>   static value * format_result_closure = NULL;
>   if (format_result_closure == NULL)
>     format_result_closure = caml_named_value("format_result");
>   return strdup(String_val(callback(*format_result_closure, Val_int(n))));
>   /* We copy the C string returned by String_val to the C heap
>      so that it remains valid after garbage collection. */
> }
> ----------------------------------------------------------
> 
> -------------------main.c---------------------------------
> /* File main.c -- a sample client for the Caml functions */
> 
> #include <stdio.h>
> 
> int main(int argc, char ** argv)
> {
>   int result;
> 
>   /* Initialize Caml code */
>   caml_startup(argv);
>   /* Do some computation */
>   result = fib(10);
>   printf("fib(10) = %s\n", format_result(result));
>   return 0;
> }
> ----------------------------------------------------------
> 
> _________________________________________________________________
> Help STOP SPAM with the new MSN 8 and get 2 months FREE*  
> http://join.msn.com/?page=features/junkmail
> 
> -------------------
> To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
> Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


-- 
`No, you don't understand,' the Knight said, looking a little vexed. 
`That's what the name is called. The name really is "The Aged Aged 
Man."'
-- Lewis Carroll

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


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

* Re: [Caml-list] Interfacing C and Ocaml
  2003-06-19 19:58 [Caml-list] Interfacing C and Ocaml Jung Woon Ho
@ 2003-06-19 20:06 ` Kip Macy
  2003-06-19 20:28 ` art yerkes
  1 sibling, 0 replies; 18+ messages in thread
From: Kip Macy @ 2003-06-19 20:06 UTC (permalink / raw)
  To: Jung Woon Ho; +Cc: caml-list

try sticking in -L<path to libcurses.so> for -lcurses

On Thu, 19 Jun 2003, Jung Woon Ho wrote:

> Hi, Im trying to implement a simple program that interfaces C and Ocaml.
> Here is what I do:
> 
>         ocamlc -custom -output-obj -o modcaml.o mod.ml
>         ocamlc -c modwrap.c
>         cp /usr/local/lib/ocaml/libcamlrun.a mod.a
>         ar r mod.a modcaml.o modwrap.o
> 	cc -o prog main.c mod.a -lcurses
> 
> and I get the error:
> /usr/lib/gcc-lib/i486-suse-linux/3.2/../../../../i486-suse-linux/bin/ld: 
> cannot find -lcurses
> collect2: ld returned 1 exit status
> 
> I tried cc -o prog main.c mod.a -lcurses -ltermcap and cc -o prog main.c 
> mod.a -ltermcap but i cant get the program to link.
> 
> Does anybody know how to solve this problem?
> 
> Thank you very much.
> 
> 
> 
> 
> ---------------------mod.ml-------------------------------
> (* File mod.ml -- some ``useful'' Caml functions *)
> 
> let rec fib n = if n < 2 then 1 else fib(n-1) + fib(n-2)
> 
> let format_result n = Printf.sprintf "Result is: %d\n" n
> 
> (* Export those two functions to C *)
> 
> let _ = Callback.register "fib" fib
> let _ = Callback.register "format_result" format_result
> ----------------------------------------------------------
> 
> --------------------modwrap.c-----------------------------
> /* File modwrap.c -- wrappers around the Caml functions */
> 
> #include <stdio.h>
> #include <string.h>
> #include <caml/mlvalues.h>
> #include <caml/callback.h>
> 
> int fib(int n)
> {
>   static value * fib_closure = NULL;
>   if (fib_closure == NULL) fib_closure = caml_named_value("fib");
>   return Int_val(callback(*fib_closure, Val_int(n)));
> }
> 
> char * format_result(int n)
> {
>   static value * format_result_closure = NULL;
>   if (format_result_closure == NULL)
>     format_result_closure = caml_named_value("format_result");
>   return strdup(String_val(callback(*format_result_closure, Val_int(n))));
>   /* We copy the C string returned by String_val to the C heap
>      so that it remains valid after garbage collection. */
> }
> ----------------------------------------------------------
> 
> -------------------main.c---------------------------------
> /* File main.c -- a sample client for the Caml functions */
> 
> #include <stdio.h>
> 
> int main(int argc, char ** argv)
> {
>   int result;
> 
>   /* Initialize Caml code */
>   caml_startup(argv);
>   /* Do some computation */
>   result = fib(10);
>   printf("fib(10) = %s\n", format_result(result));
>   return 0;
> }
> ----------------------------------------------------------
> 
> _________________________________________________________________
> Help STOP SPAM with the new MSN 8 and get 2 months FREE*  
> http://join.msn.com/?page=features/junkmail
> 
> -------------------
> To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
> Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> 

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


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

* [Caml-list] Interfacing C and Ocaml
@ 2003-06-19 19:58 Jung Woon Ho
  2003-06-19 20:06 ` Kip Macy
  2003-06-19 20:28 ` art yerkes
  0 siblings, 2 replies; 18+ messages in thread
From: Jung Woon Ho @ 2003-06-19 19:58 UTC (permalink / raw)
  To: caml-list; +Cc: unosoft

Hi, Im trying to implement a simple program that interfaces C and Ocaml.
Here is what I do:

        ocamlc -custom -output-obj -o modcaml.o mod.ml
        ocamlc -c modwrap.c
        cp /usr/local/lib/ocaml/libcamlrun.a mod.a
        ar r mod.a modcaml.o modwrap.o
	cc -o prog main.c mod.a -lcurses

and I get the error:
/usr/lib/gcc-lib/i486-suse-linux/3.2/../../../../i486-suse-linux/bin/ld: 
cannot find -lcurses
collect2: ld returned 1 exit status

I tried cc -o prog main.c mod.a -lcurses -ltermcap and cc -o prog main.c 
mod.a -ltermcap but i cant get the program to link.

Does anybody know how to solve this problem?

Thank you very much.




---------------------mod.ml-------------------------------
(* File mod.ml -- some ``useful'' Caml functions *)

let rec fib n = if n < 2 then 1 else fib(n-1) + fib(n-2)

let format_result n = Printf.sprintf "Result is: %d\n" n

(* Export those two functions to C *)

let _ = Callback.register "fib" fib
let _ = Callback.register "format_result" format_result
----------------------------------------------------------

--------------------modwrap.c-----------------------------
/* File modwrap.c -- wrappers around the Caml functions */

#include <stdio.h>
#include <string.h>
#include <caml/mlvalues.h>
#include <caml/callback.h>

int fib(int n)
{
  static value * fib_closure = NULL;
  if (fib_closure == NULL) fib_closure = caml_named_value("fib");
  return Int_val(callback(*fib_closure, Val_int(n)));
}

char * format_result(int n)
{
  static value * format_result_closure = NULL;
  if (format_result_closure == NULL)
    format_result_closure = caml_named_value("format_result");
  return strdup(String_val(callback(*format_result_closure, Val_int(n))));
  /* We copy the C string returned by String_val to the C heap
     so that it remains valid after garbage collection. */
}
----------------------------------------------------------

-------------------main.c---------------------------------
/* File main.c -- a sample client for the Caml functions */

#include <stdio.h>

int main(int argc, char ** argv)
{
  int result;

  /* Initialize Caml code */
  caml_startup(argv);
  /* Do some computation */
  result = fib(10);
  printf("fib(10) = %s\n", format_result(result));
  return 0;
}
----------------------------------------------------------

_________________________________________________________________
Help STOP SPAM with the new MSN 8 and get 2 months FREE*  
http://join.msn.com/?page=features/junkmail

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


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

* [Caml-list] Interfacing C++ and Ocaml
@ 2001-03-28  8:37 David Chemouil
  0 siblings, 0 replies; 18+ messages in thread
From: David Chemouil @ 2001-03-28  8:37 UTC (permalink / raw)
  To: caml-list


Hi,



I am in the situation where I would like to write an Ocaml program which
makes use of some C++ classes. It seems to me some people had said there
were some problems doing so, but I can't recall what these problems may
be, and didn't find anything precise in the ML archive.

So, I would like to know what may prevent me to reuse C++ code from
Ocaml, if anything may. I am sure some arrangements can be done, as
there exists an Ocaml implementation on BeOS, which is programmed in
C++. 

Moreover, if it is possible, what do you advise me to do? What are the
limitations? Have you got simple examples of such interfacings?


Thanks in advance,

dc



PS: BTW, I would like to thank these happy volunteers who aim at
packaging a Caml Development Kit. IMO, this is truly a good idea, which
may help Caml spread. Just a question to the Caml team: I would like to
know if you intend to include polymorphic I/O and some kind of
overloading in a forthcoming release of Caml. It seems to me Pierre had
written some mails about this, but is is now a long time ago, how is the
situation today?


-- 
David Chemouil    [mailto:David.Chemouil@irit.fr]

Institut de recherche en informatique de Toulouse
-------------------
To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr


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

end of thread, other threads:[~2003-06-27  8:34 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-03-30  8:54 [Caml-list] Interfacing C++ and Ocaml David Chemouil
2001-03-30  9:13 ` Bruce Hoult
2001-03-30  9:24   ` Fergus Henderson
2001-03-30 16:50 ` Overloading again (Was Re: [Caml-list] Interfacing C++ and Ocaml) Brian Rogoff
2001-04-02  8:13   ` Jean-Marc Alliot
2001-04-02 13:48     ` Fergus Henderson
2001-04-02 14:30       ` Jean-Marc Alliot
2001-04-02 15:49         ` Brian Rogoff
2001-04-09  6:47           ` John Max Skaller
2001-04-02 15:51     ` Brock
  -- strict thread matches above, loose matches on Subject: below --
2003-06-26 14:42 [Caml-list] interfacing C and OCaml Jung Woon Ho
2003-06-26 15:14 ` Lex Stein
2003-06-26 19:02 ` Jean-Baptiste Rouquier
2003-06-27  5:24   ` Re[2]: " Mikhail Fedotov
2003-06-27  8:31     ` Jean-Baptiste Rouquier
2003-06-19 19:58 [Caml-list] Interfacing C and Ocaml Jung Woon Ho
2003-06-19 20:06 ` Kip Macy
2003-06-19 20:28 ` art yerkes
2001-03-28  8:37 [Caml-list] Interfacing C++ " David Chemouil

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