[Rd] linking hdf5, requires setting LD_LIBRARY_PATH

Dirk Eddelbuettel edd at debian.org
Wed Mar 3 02:45:08 CET 2010

Unless I am missing something, this has nothing to do with hdf5 per se. See

On 2 March 2010 at 16:20, bullard at stat.Berkeley.EDU wrote:
| I am writing an R package to interface to hdf5 files (yes I know one
| exists, the issue will be demonstrated using that package). I tend to like
| to build/install things locally so that aspects of the system I am working
| on don't cause problems later when attempting to install elsewhere. To
| this end, I build and install the hdf5 libraries w/out incident:
| tar xzf hdf5-1.8.4.tar.bz2
| cd hdf5-1.8.4
| ./configure --prefix=/home/jbullard/scratch/hdf5_install
| make && make install
| Now, I make a shared object using the following (I am compiling hdf5.c
| directly in src of the hdf5 package):
| gcc -I/home/jbullard/projects/me/R-builder/lib64/R/include
| -I/home/jbullard/scratch/hdf5_install/include -I/usr/local/include -fpic
| -g -O2 -std=gnu99 -c hdf5.c -o hdf5.o
| gcc -shared -L/usr/local/lib64 -o hdf5.so hdf5.o
| -L/home/jbullard/scratch/hdf5_install/lib -lhdf5 -lz -lm
| -L/home/jbullard/projects/me/R-builder/lib64/R/lib -lR
| I then start R and get the following error:
| Error in dyn.load("hdf5.so") :
|   unable to load shared library '/home/jbullard/scratch/hdf5/src/hdf5.so':
|   libhdf5.so.6: cannot open shared object file: No such file or directory
| The solution is set LD_LIBRARY_PATH to
| /home/jbullard/scratch/hdf5_install/lib

Of course. This is a dynamic library, and ld.so needs to find it.  

So if and when _you_ opt to depart from using standard locations, _you_ need
to tell ld.so where to look.

Setting LD_LIBRARY_PATH is one of several ways to do so. Others include 

  a) the /etc/ld.so.conf file, 

  b) (on newer linuxen) a file in the /etc/ld.so.conf.d/ directory

  c) encode the path at link time using the rpath argument.

Rcpp and RInside provide examples of the last approach.

Hth, Dirk

| Then things work just fine. However, I dislike this option -- Is there any
| other way which things can be orchestrated completely at package install
| time? I don't want to go editing any files in the R installation; more
| like an option to append something to R's LD_LIBRARY_PATH w/in the
| Makevars.in of the package being installed (in this case, hdf5)?
| Details of platform below. As always, thanks in advance.
| jim
| R version 2.11.0 Under development (unstable) (2010-02-08 r51110)
| x86_64-unknown-linux-gnu
| locale:
|  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C
|  [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8
|  [5] LC_MONETARY=C              LC_MESSAGES=en_US.UTF-8
|  [7] LC_PAPER=en_US.UTF-8       LC_NAME=C
|  [9] LC_ADDRESS=C               LC_TELEPHONE=C
| attached base packages:
| [1] stats     graphics  grDevices utils     datasets  methods   base
| HDF5 Version 1.8.4
| R hdf5 package: hdf5_1.6.9.tar.gz
| Linux mp-1246 2.6.31-19-generic #56-Ubuntu SMP Thu Jan 28 02:39:34 UTC
| 2010 x86_64 GNU/Linux
| ______________________________________________
| R-devel at r-project.org mailing list
| https://stat.ethz.ch/mailman/listinfo/r-devel

  Registration is open for the 2nd International conference R / Finance 2010
  See http://www.RinFinance.com for details, and see you in Chicago in April!

More information about the R-devel mailing list