Version française
Home     About     Download     Resources     Contact us    
Browse thread
"Hello web" please
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Jonathan Hayward <christos.jonathan.hayward@g...>
Subject: Re: [Caml-list] "Hello web" please
Thank you; it seems to compile now, but it's crashing (runtime); there's a
library installed on my system that it's not picking up.

The error message is:

jonathan@inner-sanctum:~/csi/ml$ ocamlrun ocaml ./
Cannot load required shared library dllpcre_stubs.
Reason: cannot open shared object file: No such file or
Reference to undefined global `Pcre'

Slocate finds the library in /usr/lib/ocaml/3.08.3/stublibs/
; do I need to tell the script to search there?

The script (missing " in" appended to the appropriate line) is:

#!/usr/bin/ocamlrun ocaml

(* Change the directories as needed for your system. *)
#directory "/usr/lib/ocaml/3.08.3/pcre";;
#load "pcre.cma";;
#load "unix.cma";;
#directory "/usr/lib/ocaml/3.08.3/netstring";;
#load "netstring.cma";;
#directory "/usr/lib/ocaml/3.08.3/cgi/";;
#load "netcgi.cma";;

open Netcgi

let text = Netencoding.Html.encode_from_latin1
  (* This function encodes "<", ">", "&", double quotes, and Latin 1
     characters as character entities.  E.g. text "<" = "&lt;", and
     text "ä" = "&auml;" *)

(* Normally you would use a template system instead of this *)
let html_page (cgi:cgi) title html =
  let out = cgi#out_channel#output_string in
  out "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \
  out ("<html>\n<head><title>" ^ text title ^"</title></head>
  out html;
  out "</body>\n</html>"

let main (cgi:cgi) =
    ~content_type:"text/html; charset=\"iso-8859-1\""
  let foo = cgi#argument_value "foo" in
  let html = match foo with
    | "1" -> "Yes"
    | "0" -> "No"
    | _ -> "Undefined" in
  html_page cgi foo html

(* You can buffer or not the output.  If buffered you can rollback
   (useful in case of error). You can replace by
   another connector entry point (FCGI, SCGI, AJP, Apache mod). *)
let () =
  let buffered _ ch = new Netchannels.buffered_trans_channel ch in ~output_type:(`Transactional buffered) main


++ Jonathan Hayward,
** To see an award-winning website with stories, essays, artwork,
** games, and a four-dimensional maze, why not visit my home page?
** All of this is waiting for you at

** If you'd like a Google Mail ( account, please tell me!