From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 7A4EDBB83 for ; Tue, 18 Jul 2006 17:32:51 +0200 (CEST) Received: from mail.cs.unm.edu (mail.cs.unm.edu [64.106.20.33]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id k6IFWofd009880 for ; Tue, 18 Jul 2006 17:32:51 +0200 Received: from localhost (localhost.localdomain [127.0.0.1]) by mail.cs.unm.edu (Postfix) with ESMTP id D2D28E4284; Tue, 18 Jul 2006 09:32:47 -0600 (MDT) Received: from mail.cs.unm.edu ([127.0.0.1]) by localhost (mail [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 13472-04; Tue, 18 Jul 2006 09:32:47 -0600 (MDT) Received: from io.cs.unm.edu (io.cs.unm.edu [64.106.21.21]) by mail.cs.unm.edu (Postfix) with ESMTP id 822E8E4270; Tue, 18 Jul 2006 09:32:47 -0600 (MDT) Date: Tue, 18 Jul 2006 09:33:19 -0600 (MDT) From: "William D. Neumann" To: Julien Michel Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Unix module troubles & Time functions In-Reply-To: <20060718121035.hy7o1wa1cmhus4g0@webmailetu.univ-orleans.fr> Message-ID: References: <20060718121035.hy7o1wa1cmhus4g0@webmailetu.univ-orleans.fr> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at cs.unm.edu X-Miltered: at concorde with ID 44BCFF22.002 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; unix:01 ocamlc:01 -custom:01 unix:01 dup:01 dup:01 gettimeofday:01 gettimeofday:01 module's:01 mlvalues:01 alloc:01 camlprim:01 struct:01 timeval:01 failwith:01 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.3 On Tue, 18 Jul 2006, Julien Michel wrote: > and trying to compile this way: > ocamlc -custom -o main unix.cma *ml > returns this error while executing on my target: > Fatal error: unknown C primitive `unix_dup\' > > What can be wrong with my system so that I cannot use the Unix.module? Well, you don't have the dup functionality available. Possibly other things are missing as well. You cauld look into how the Unix build is configured and modify it to skip the functionality you don't have (or better yet raise an exception). But that might be more work than you need. > The Gettimeofday unix function usually works well on my target, is there another > way for having access to it with Caml? Yes. You can write your own interface to the gettimeofday function (that's all the Unix module's function is). timer.c ==================================================================== #include #include #include #include #include CAMLprim value my_gettimeofday(value unit) { struct timeval tp; if (gettimeofday(&tp, NULL) == -1) caml_failwith("gettimeofday: failure"); return copy_double((double) tp.tv_sec + (double) tp.tv_usec / 1e6); } ==================================================================== timer.ml ==================================================================== external timeofday : unit -> float = "my_gettimeofday" let _ = let t1 = timeofday () and t2 = Unix.gettimeofday () in Printf.printf "mytime: %f, utime: %f\n" t1 t2;; ==================================================================== [414] 9:24AM% ocamlc timer.c [415] 9:29AM% ocamlc -custom -o timer.bc timer.o unix.cma timer.ml [416] 9:29AM% ./timer.bc mytime: 1153236588.033843, utime: 1153236588.033860 (Note, you won't have the Unix module, so you don't need the unix.cma part when you compile your use of the new timeofday function, I just neede it to compare to the Unix.gettimeofday function) Read chapter 18 of the OCaml manual for more info on interfacing OCaml with C. William D. Neumann --- "There's just so many extra children, we could just feed the children to these tigers. We don't need them, we're not doing anything with them. Tigers are noble and sleek; children are loud and messy." -- Neko Case Life is unfair. Kill yourself or get over it. -- Black Box Recorder