Version française
Home     About     Download     Resources     Contact us    
Browse thread
OCaml/C interface
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Nathan Mishra Linger <nathan.mishralinger@g...>
Subject: Re: [Caml-list] OCaml/C interface
On 10/26/07, Julien Moutinho <julien.moutinho@gmail.com> wrote:
>
> On Thu, Oct 25, 2007 at 03:17:43PM -0700, Nathan Mishra Linger wrote:
> > Having just read Chapter 18 of the manual regarding "Interfacing C with
> > OCaml", I wrote a simple program to test my understanding.  However,
> when I
> > try to compile it I run into some undefined symbol problems (_tgetent,
> > _tgetnum, etc).  My machine is a PowerPC iBook G4 running OS X 10.4.10.
> >
> > Does anyone know how to fix this?  After Googling around, I think this
> is a
> > Mac problem rather than an OCaml one, but I thought people on this list
> > might have come up against this same problem.  Also, any comments on my
> C
> > code that calls OCaml would be appreciated.
>
> A solution may be:
>
> % ls
> Makefile Makefile.old test.c test.c.old test.ml
>
> % diff -U 0 Makefile.old Makefile
> --- Makefile.old        2007-10-26 11:07:41.000000000 +0200
> +++ Makefile    2007-10-26 11:11:34.000000000 +0200
> @@ -5 +5 @@
> -       cc -o myprog test.o camlcode.o -L/usr/local/lib/ocaml -lcamlrun
> +       cc -o myprog test.o camlcode.o -L/usr/local/lib/ocaml -lcamlrun
> -lm -lcurses
>
> % diff -u test.c.old test.c
> --- test.c.old  2007-10-26 11:06:33.000000000 +0200
> +++ test.c      2007-10-26 11:02:42.000000000 +0200
> @@ -25,9 +25,10 @@
> int main() {
>    CAMLlocal1(xs);
>    char* argv[]  = {"yo"};
> -  caml_main(argv);
> +  caml_startup(argv);
>    xs = up_to(5);
>    gc();
>    printf("sum of [1..5] = %i\n", sum(xs));
> +  return EXIT_SUCCESS;
> }
>
> % make
> ocamlc -c test.ml
> cc -I/usr/local/lib/ocaml -c test.c
> ocamlc -output-obj -o camlcode.o test.cmo
> cc -o myprog test.o camlcode.o -L/usr/local/lib/ocaml -lcamlrun -lm
> -lcurses
>
> % ./myprog
> sum of [1..5] = 15
>
> HTH,
>   Julien.



Yep.  That did it.  Thanks, Julien!

Nathan