[PPL-devel] Bugs in OCaml interface

Kenneth MacKenzie kwxm at inf.ed.ac.uk
Fri Apr 3 11:11:39 CEST 2009


Enea Zaffanella writes:

 [About make check]. 
 > 
 > This looks strange to me: the message seems to suggest that the system 
 > finds the OCaml mlgmp wrapper, but it does not find the C++ wrapper 
 > libgmpxx.
 > 
 > I am definitely not an expert of OCaml related builds, but I think that 
 > I have read somewhere that OCaml native library wrappers were encoding 
 > in their inside the right link options, so that one should not need to 
 > issue them each time.
 > 
 > I will need to investigate further, but for the immediate I can imagine 
 > two possible explanations :
 > 
 > a) Maybe you did something wrong when compiling the mlgmp wrapper.
 > As said in file interfaces/Ocaml/README.ocaml:
 > ===========
 > In order to install MLGMP you should make sure that GMP_INCLUDES and
 > GMP_LIBDIR are correctly set (these variables are defined at the
 > beginning of Makefile in the MLGMP's root directory).
 > ===========
 > Could it be the case that you did something wrong here?
 > 

No, MLGMP's OK.

 > b) What is the output of the command
 >     echo $LD_LIBRARY_PATH
 > on your machine? Does it include the path to your installation place, 
 > that is /afs/inf.ed.ac.uk/user/k/kwxm/libraries/lib ?
 > 
 > Let us know if either a) or b) solves the problem.
 > 

   I have to admit that I'm very confused by this.  I don't have
LD_LIBRARY_PATH set, and you're correct in suggesting that if I set it
to point to the location of my libraries then the test works OK.
However, I've been able to compile and link my own programs without
the use of LD_LIBRARY_PATH with no problems, and I can also compile
your test program without using it.  Here are the commands which
interfaces/OCcaml/tests/Makefile executes when it's compiling test1:

OCAMLRUNPARAM='l=1M' ocamlc -o test1.cmo -c -I /home/kwxm/libraries/lib -I .. -ccopt -g test1.ml
OCAMLRUNPARAM='l=1M' ocamlc -o test1 \
		-cc "g++" -I /home/kwxm/libraries/lib -I .. -ccopt -g \
		-cclib ../../../src/.libs/libppl.so -cclib ../../../Watchdog/src/.libs/libpwl.so -cclib -lmlgmp -cclib -lmpfr `echo " -lm -L/home/kwxm/libraries/lib -lgmpxx -L/home/kwxm/libraries/lib -lgmp -R/home/kwxm/libraries/lib -R/home/kwxm/libraries/lib " | /bin/sed -e "s/ -R[^ ]*//g" -e "s/ -/ -cclib -/g"` \
		ppl_ocaml.cma test1.cmo

Note that the second command, which does the linking, explicitly
mentions things like libppl.so and -lgmpxx.

If you run the above commands and then use ldd, you get the following:

 ldd test1
	linux-gate.so.1 =>  (0xb7fc4000)
	libgmpxx.so.4 => not found
	libgmp.so.3 => /usr/lib/libgmp.so.3 (0xb7f4e000)
	libppl.so.7 => not found
	libpwl.so.4 => not found
	libmpfr.so.1 => /usr/lib/libmpfr.so.1 (0xb7f0b000)
        ...

So in spite of all the options, it still doesn't know where to find
libgmpxx.so.  It turns out that if you make a directory containing
only libgmpxx.so.4 and point LD_LIBRARY_PATH to it, then test1 still
fails because it can't find libppl.so.7, and similarly for libpwl.so.4.
Once it's got all of these it works OK though.

I spent some time experimenting and found that I could do the
compilation with much simpler commands.  To avoid the danger of
interacting with my own previously-compiled version of PPL and other
libraries, I made a directory called ~/gmp containing libgmp.a and
libgmp.so*, together with the files gmp.a, gmp.cma and gmp.cmxa from
mlgmp.  I can compile test1.ml by saying

ocamlc -c -o test1.cmo -I ~/gmp -I .. test1.ml

This is pretty much the same as what's in the makefile.  I think that
at this stage it just needs to be able to find the .cma files for the
OCaml modules used by test1.


After this, I can link test1 with

ocamlc -o test1 ../ppl_ocaml.cma ~/gmp/gmp.cma test1.cmo  \
-cclib -lppl -cclib -lpwl

(instead of using ../ppl_ocaml.cma you can also say
-I .. ppl_ocaml.cma,  and similarly for gmp)

After this test1 runs successfully.

Note that I don't have to refer to -lgmp or any of the other libraries
(but you can't leave out -lppl or -lpwl).  If you type 
"strings ../ppl_ocaml.cma" then at the very end you see some strings which
mention stuff like -L/home/kwxm/libraries/lib and -lgmpxx, so I think
the ocaml compiler records some of the information that's necessary for
the final linking.


[Some time later...]

Ah, now I see that what makes the difference is including gmp.cma in
the linking command.  If you insert it just after libppl.so in the
makefile then everything works OK, and I think most of the other
options are unnecessary.  I still don't understand exactly what's
going on though.  :(


Kenneth


PS:  my problematic BHRZ03 widening just finished, after 31 hours and
40 minutes.  The result was the same as that of the H79 widening.

-- 
The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.




More information about the PPL-devel mailing list