<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE message PUBLIC
  "-//MLarc//DTD MLarc output files//EN"
  "../../mlarc.dtd"[
  <!ATTLIST message
    listname CDATA #REQUIRED
    title CDATA #REQUIRED
  >
]>

  <?xml-stylesheet href="../../mlarc.xsl" type="text/xsl"?>


<message 
  url="2003/07/2aadf483f3e89d9c785e4c8aa61c83c5"
  from="Basile STARYNKEVITCH &lt;basile@s...&gt;"
  author="Basile STARYNKEVITCH"
  date="2003-07-25T08:37:09"
  subject="[Caml-list] static linking behavior of Ocaml w.r.t Dbm"
  prev="2003/07/72f5923f5c7f08eabc76024172d3b76b"
  next="2003/07/fcd2e53c5f8bbda689e3fd935be33515"
  prev-thread="2003/07/21b30d51ac7b7eb8664b299a9cdf73e8"
  next-thread="2003/07/3df9d69f6b18b9279873b911297d0c59"
  root="../../"
  period="month"
  listname="caml-list"
  title="Archives of the Caml mailing list">

<thread subject="[Caml-list] static linking behavior of Ocaml w.r.t Dbm">
<msg 
  url="2003/07/2aadf483f3e89d9c785e4c8aa61c83c5"
  from="Basile STARYNKEVITCH &lt;basile@s...&gt;"
  author="Basile STARYNKEVITCH"
  date="2003-07-25T08:37:09"
  subject="[Caml-list] static linking behavior of Ocaml w.r.t Dbm">
</msg>
</thread>

<contents>
Dear All,

(I'm BCC the poesia-devel list, since the problem was first identified
for compilation of POESIA monitor. See http://poesia.sourceforge.net
and http://www.poesia-filter.org for more)

on the Debian Sid systems I've got it is not possible to easily
compile *statically* a program using Dbm. Consider the following (self
contained but usable) test program:


################################################################
(* file testdbm.ml *)
let dbopt = ref (None : Dbm.t option);;

let keyref = ref "";;

let dbpathref = ref "";;

let get_db () = match !dbopt with 
  None -&gt; failwith "no db"
| Some db -&gt; db;;

let main () =
  Arg.parse 
    [
      "-C", Arg.String (fun path -&gt; 
			  let db = Dbm.opendbm path 
				     [ Dbm.Dbm_create; Dbm.Dbm_rdwr ] 0o640 
			  in 
			    dbopt := (Some db); 
			    dbpathref := path;
			    Printf.printf "created dbm %S\n" path), 
      "create a Dbm" ;
      "-R", Arg.String (fun path -&gt; 
			  let db = Dbm.opendbm path 
				     [ Dbm.Dbm_create; Dbm.Dbm_rdonly ] 0o640 
			  in
			    dbopt := (Some db); 
			    dbpathref := path; 
			    Printf.printf "reading dbm %S\n" path),
      "open a readonly Dbm" ;
      "-W", Arg.String (fun path -&gt; 
			  let db = Dbm.opendbm path 
				     [ Dbm.Dbm_create; Dbm.Dbm_rdonly ] 0o640 
			  in 
			    dbopt := (Some db); 
			    dbpathref := path; 
			    Printf.printf "writing (&amp;reading) dbm %S\n" path),
      "open a readwrite Dbm" ;
      "-K", Arg.String (fun key -&gt;
			  keyref := key),
      "set the current key" ;
      "-P", Arg.String (fun vals -&gt;
			  Dbm.add (get_db ()) !keyref vals;
			  Printf.printf "put key=%S val=%S in dbm %S\n" 
			    !keyref vals !dbpathref),
      "put a value" ;
      "-D", Arg.Unit (fun () -&gt;
			Dbm.remove (get_db ()) !keyref ;
			Printf.printf "deleted key=%S in dbm %S\n"
			  !keyref !dbpathref),
      "delete a value" ;
      "-G", Arg.Unit (fun () -&gt;
			let vals = Dbm.find (get_db ()) !keyref in
			  Printf.printf "got key=%S val=%S in dbm %S\n"
			    !keyref vals !dbpathref),
      "get a value" ;
      "-A", Arg.Unit (fun () -&gt;
			Dbm.iter 
			(fun k v -&gt; Printf.printf "has key=%S val=%S\n" k v) 
			(get_db ())),
      "dump all bindings" ]
    (fun arg -&gt; failwith (" unexpected arg " ^ arg))
    "testdbm" ;
  match !dbopt with 
      None -&gt; ()
    | Some db -&gt; Dbm.close db;;

Printexc.print main ();;
(* eof testdbm.ml *)
################################################################

Save the above in a file testdbm.ml; then run
   /usr/bin/ocamlopt -cclib -static dbm.cmxa testdbm.ml -o testdbm

You get a lot of messages like 
/usr/lib/gcc-lib/i386-linux/3.3.1/../../../libgdbm_compat.a(dbmopen.o)(.text+0xc6): In function `dbm_open':
: undefined reference to `gdbm_open'
/usr/lib/gcc-lib/i386-linux/3.3.1/../../../libgdbm_compat.a(dbmopen.o)(.text+0x135): In function `dbm_open':

Removing the -cclib -static or adding -cclib /usr/lib/libgdbm.a solves
the problem

I just got the latest Ocaml from CVS, compiled and installed it
   /usr/local/bin/ocamlopt -v
   The Objective Caml native-code compiler, version 3.07+beta 1
   Standard library directory: /usr/local/lib/ocaml
and it does not exhibit the above problem.

I don't know if it is a problem of Debian packaging, or an Ocaml 3.06
problem solved in 3.07

As a temporary workaround across a bug in Ocaml 3.06 in Debian Sid
(and perhaps other distributions), I suggest to Poesia users to add
the required -cclib option to the OPTLIBS makefile variable.
-- 

Basile STARYNKEVITCH         http://starynkevitch.net/Basile/ 
email: basile&lt;at&gt;starynkevitch&lt;dot&gt;net 
aliases: basile&lt;at&gt;tunes&lt;dot&gt;org = bstarynk&lt;at&gt;nerim&lt;dot&gt;net
8, rue de la Faïencerie, 92340 Bourg La Reine, France

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners

</contents>

</message>

