caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Nathan Mishra Linger" <nathan.mishralinger@gmail.com>
To: "OCaml List" <caml-list@yquem.inria.fr>
Subject: OCaml/C interface
Date: Thu, 25 Oct 2007 15:17:43 -0700	[thread overview]
Message-ID: <ab0c618e0710251517p3ab42e64m64dbe7c886193f5e@mail.gmail.com> (raw)

[-- 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 --]

             reply	other threads:[~2007-10-26  7:02 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-10-25 22:17 Nathan Mishra Linger [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ab0c618e0710251517p3ab42e64m64dbe7c886193f5e@mail.gmail.com \
    --to=nathan.mishralinger@gmail.com \
    --cc=caml-list@yquem.inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).