[R-pkg-devel] Linking external libraries in non-standard locations

Iñaki Úcar i.ucar86 at gmail.com
Sat Jun 17 17:30:57 CEST 2017

Hi all,

After googling around for a while, I found that this is a common
problem, but still it is not clear to me how I should handle this.

I have a package A, with C++ code via Rcpp, that needs an external C++
library libB. I have a configure script that sets

PKG_LIBS=-L/path/to/B/lib -lB

in src/Makevars. Compilation and linking seem to go just fine. But then,

** testing if installed package can be loaded
Error in dyn.load(file, DLLpath = DLLpath, ...) :
  unable to load shared object
  libB.so: cannot open shared object file: No such file or directory

If I set LD_LIBRARY_PATH=/path/to/B/lib, the error above is solved and
the package is installed. But then I try to load the package with
library(A), with LD_LIBRARY_PATH still set, and the same error

So what is the proper and more portable way of linking a external
library in a non-standard location?


More information about the R-package-devel mailing list