From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: * X-Spam-Status: No, score=1.4 required=5.0 tests=HTML_MESSAGE,SPF_NEUTRAL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id 3E67DBCC2 for ; Fri, 26 Oct 2007 09:02:29 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAAKzIEfRVca8mGdsb2JhbACCPDaLaAIBAQcCBhMY X-IronPort-AV: E=Sophos;i="4.21,330,1188770400"; d="scan'208";a="18617470" Received: from rv-out-0910.google.com ([209.85.198.188]) by mail4-smtp-sop.national.inria.fr with ESMTP; 26 Oct 2007 00:17:45 +0200 Received: by rv-out-0910.google.com with SMTP id k20so581915rvb for ; Thu, 25 Oct 2007 15:17:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:mime-version:content-type; bh=3wKXo6vqLDImmkUXcWpKdFgtTvXuQ0CSnA4phWyaB3c=; b=LlDFAKH16TqM6ffkKQsA8lnqISvexPuegRKGalmDKreAQ8PDjyoLaPLkjctr9G9jTnfLT/EQM+VVmLGb3koaq885YHGEkeHT67Fcx8uHaYQoYsNjM/R1mV0MW88X2+vEhw9K02Mfs6sQdYNfIjMYGtxsIXzllgU+LzDITFp3Q6o= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:mime-version:content-type; b=iU9cxnAE6XjaYFDHWK740UhbldrU7MHeelYcl2BEKuAK5fYrYZUJ+j6m6sDvOVRPKgu5exy7W+w7tq+DceeWpCzDpqsSScHZcQFTYfR1Nel+RF+ay8GYju9St/qzI+bengqmlJoP8uTOEdx/KWCwBpAds2MGf0lTanEytPuxpA4= Received: by 10.140.132.8 with SMTP id f8mr1208158rvd.1193350663203; Thu, 25 Oct 2007 15:17:43 -0700 (PDT) Received: by 10.140.225.18 with HTTP; Thu, 25 Oct 2007 15:17:43 -0700 (PDT) Message-ID: Date: Thu, 25 Oct 2007 15:17:43 -0700 From: "Nathan Mishra Linger" To: "OCaml List" Subject: OCaml/C interface MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_1767_24984235.1193350663197" X-Spam: no; 0.00; ocaml:01 interfacing:01 ocaml:01 powerpc:01 stdio:01 mlvalues:01 camlparam:01 camlreturn:01 val:01 val:01 camlparam:01 camlreturn:01 argv:01 argv:01 printf:01 ------=_Part_1767_24984235.1193350663197 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline 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 /* 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 ------=_Part_1767_24984235.1193350663197 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline
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

------=_Part_1767_24984235.1193350663197--