土足で窓から失礼いたします。今日からあなたの息子になります。 当年とって92歳、下町の発明王、エジソンです。





今回はversion 3.0beta2のインストールをしました。(執筆時最新)

$ wget http://download.camlcity.org/download/ocamlnet-3.0test2.tar.gz
$ tar xzf ocamlnet-3.0test2.tar.gz
$ cd ocamlnet-3.0test2
$ ./configure
Welcome to Ocamlnet version 3.0test2
Checking operating system... Generic
Checking for findlib... found
Checking multi-threading support... posix (ok)
Checking word size... 64 bit
Checking for PCRE... found
Checking whether Ocaml has Printexc.register_printer... ./configure: line 27: code_printexc_register_printer: command not found
Checking whether Ocaml has fancy page tables... found
Checking for POSIX shared memory... found
Checking for POSIX semaphores... not found
Checking for POSIX fadvise... not found
Checking for POSIX fallocate... not found
Checking for POSIX memalign... found
Checking for POSIX pthread... found
Checking for syslog... found
Checking for GPROF... found
Checking for win32... no

Effective options:
    -bindir /opt/local/bin
    -datadir /opt/local/lib/ocaml/site-lib/netstring

Writing Makefile.conf

Please check Makefile.conf.

You can now compile Ocamlnet by invoking
   make all
for the bytecode compiler, and optionally by invoking
   make opt
for the native-code compiler (if supported on your architecture).
Finally, a
   make install
will install the package(s).


$ make all
$ sudo make install

無事インストールも完了。使えるかテストします。まずはインタプリタ。「トップレベルでロードする」という意味がわからず5分ぐらいGoogle先生にご指導いただいた。Mac OSで実行した場合はすんなりできたけど、Ubuntuのほうでは、.ocamlinitに設定が必要でした。

$ vim .ocamlinit
+ #use "topfind"


$ ocaml
        Objective Caml version 3.11.2

Findlib has been successfully loaded. Additional directives:
  #require "package";;      to load a package
  #list;;                   to list the available packages
  #camlp4o;;                to load camlp4 (standard syntax)
  #camlp4r;;                to load camlp4 (revised syntax)
  #predicates "p,q,...";;   to set these predicates
  Topfind.reset();;         to force that packages will be reloaded
  #thread;;                 to enable threads

# #use "http_get.ml";;
/opt/local/lib/ocaml/unix.cma: loaded
/opt/local/lib/ocaml/bigarray.cma: loaded
/opt/local/lib/ocaml/site-lib/netsys: added to search path
/opt/local/lib/ocaml/site-lib/netsys/netsys_oothr.cmo: loaded
/opt/local/lib/ocaml/site-lib/netsys/netsys.cma: loaded
/opt/local/lib/ocaml/site-lib/equeue: added to search path
/opt/local/lib/ocaml/site-lib/equeue/equeue.cma: loaded
/opt/local/lib/ocaml/site-lib/pcre: added to search path
/opt/local/lib/ocaml/site-lib/pcre/pcre.cma: loaded
/opt/local/lib/ocaml/site-lib/netstring: added to search path
/opt/local/lib/ocaml/site-lib/netstring/netstring.cma: loaded
/opt/local/lib/ocaml/site-lib/netstring/netstring_top.cmo: loaded
/opt/local/lib/ocaml/site-lib/netstring/netaccel.cma: loaded
/opt/local/lib/ocaml/site-lib/netstring/netaccel_link.cmo: loaded
/opt/local/lib/ocaml/site-lib/netclient: added to search path
/opt/local/lib/ocaml/site-lib/netclient/netclient.cma: loaded
val get_and_print : string -> unit = <fun>


(* #require "netclient";; *)

(* This example shows how to get a file from a HTTP server using
 * the Convenience module.
 * Load this into the toplevel, then:
 * get_and_print "http://www.caml.org/";;

open Http_client.Convenience;;

let get_and_print url =
  let s = http_get url in
  print_string s;
  flush stdout

get_and_print "http://www.caml.org/";


$ ocamlfind ocamlc -o http_get -linkpkg -package netclient http_get.ml


$ ./http_get
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">