caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* OCaml/C interface
@ 2007-10-25 22:17 Nathan Mishra Linger
  2007-10-26  9:18 ` [Caml-list] " Julien Moutinho
  0 siblings, 1 reply; 7+ messages in thread
From: Nathan Mishra Linger @ 2007-10-25 22:17 UTC (permalink / raw)
  To: OCaml List

[-- Attachment #1: Type: text/plain, Size: 2045 bytes --]

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.

Thanks,
Nathan

==================================
prompt$ cat test.ml

let rec from_to x y = if x > y then [] else x :: from_to (x+1) y
let sum_list xs = List.fold_left (+) 0 xs

let _ = Callback.register "from_to" from_to
let _ = Callback.register "sum_list" sum_list
let _ = Callback.register "gc" Gc.full_major

prompt$ cat test.c
/* C includes */
#include <stdio.h>

/* OCaml includes */
#include "caml/mlvalues.h"
#include "caml/memory.h"
#include "caml/callback.h"

value up_to(int n) {
  CAMLparam0();
  CAMLreturn(caml_callback2(*caml_named_value("from_to"), Val_int(1),
Val_int(n)));
}

void gc(void) {
  caml_callback(*caml_named_value("gc"), Val_unit);
  return;
}

int sum(value xs) {
  CAMLparam1(xs);
  CAMLreturn(Int_val(caml_callback(*caml_named_value("sum_list"), xs)));
}

int main() {
  CAMLlocal1(xs);
  char* argv[]  = {"yo"};
  caml_main(argv);
  xs = up_to(5);
  gc();
  printf("sum of [1..5] = %i\n", sum(xs));
}

prompt$ cat Makefile
all:
        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

clean:
        rm *.cm? *.o

prompt$ 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
/usr/bin/ld: Undefined symbols:
_tgetent
_tgetnum
_tgetstr
_tputs
collect2: ld returned 1 exit status
make: *** [all] Error 1

[-- Attachment #2: Type: text/html, Size: 2757 bytes --]

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

end of thread, other threads:[~2007-10-28 15:38 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-10-25 22:17 OCaml/C interface Nathan Mishra Linger
2007-10-26  9:18 ` [Caml-list] " Julien Moutinho
2007-10-26 18:13   ` Nathan Mishra Linger
2007-10-28 12:36     ` David Teller
2007-10-28 13:34       ` skaller
2007-10-28 13:48       ` Christopher L Conway
2007-10-28 15:39         ` David Teller

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