caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [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; 16+ 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] 16+ 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; 16+ 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] 16+ messages in thread
* [Caml-list] Interfacing C++ and Ocaml
@ 2001-03-30  8:54 David Chemouil
  2001-03-30  9:13 ` Bruce Hoult
  0 siblings, 1 reply; 16+ 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] 16+ messages in thread
* [Caml-list] Interfacing C++ and Ocaml
@ 2001-03-28  8:37 David Chemouil
  0 siblings, 0 replies; 16+ 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] 16+ messages in thread

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

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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-27  8:59       ` Re[2]: " Mikhail Fedotov
2003-06-27 12:57         ` art yerkes
2003-06-27 13:14           ` Re[4]: " Mikhail Fedotov
2003-06-27 17:45             ` art yerkes
  -- strict thread matches above, loose matches on Subject: below --
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-30  8:54 [Caml-list] Interfacing C++ " David Chemouil
2001-03-30  9:13 ` Bruce Hoult
2001-03-30  9:24   ` Fergus Henderson
2001-03-28  8:37 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).