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

2017-06-17 Thread Iñaki Úcar
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_CPPFLAGS=-I/path/to/B/include
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
'/home/xxx/R/x86_64-redhat-linux-gnu-library/3.3/A/libs/A.so':
  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
reappears.

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

Regards,
Iñaki

__
R-package-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-package-devel

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

2017-06-17 Thread Dirk Eddelbuettel

On 17 June 2017 at 17:30, Iñaki Úcar wrote:
| 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_CPPFLAGS=-I/path/to/B/include
| 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
| '/home/xxx/R/x86_64-redhat-linux-gnu-library/3.3/A/libs/A.so':
|   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
| reappears.
| 
| So what is the proper and more portable way of linking a external
| library in a non-standard location?

In short, I fear there is none.

The _dynamic_ linker needs to know where the library is. There are defaults,
and there are ways to extend this (i.e. /etc/ld.so.conf.d/*conf on the OS I
use, or LD_LIBRARY_PATH as you used) but _none of those means are accessible
to an R package_. This is system dependent.

A static library you can control for yourself in your package.

Dirk

-- 
http://dirk.eddelbuettel.com | @eddelbuettel | e...@debian.org

__
R-package-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-package-devel


[R-pkg-devel] Compiler optimization flags with R package

2017-06-17 Thread Guillaume Chapron
Hello,

I am trying to debug some C code that is run only through a R package. I debug 
with lldb but I always get a message telling that the package "was compiled 
with optimization - stepping may behave oddly; variables may not be available.” 
And in fact, I cannot evaluate all variables and understand what is wrong. I 
have created a Makevars file in ~/.R/ that contains C=clang -O0 -g but it does 
not seem to change much. What should I do to make sure I can evaluate all 
variables in lldb? I am on a Mac and I wrote C=clang because I read that it 
produced much better error messages but I am happy to use gcc as well if this 
can be a solution.

Many thanks

Guillaume
__
R-package-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-package-devel

Re: [R-pkg-devel] Compiler optimization flags with R package

2017-06-17 Thread Dirk Eddelbuettel

On 17 June 2017 at 21:32, Guillaume Chapron wrote:
| I am trying to debug some C code that is run only through a R package. I 
debug with lldb but I always get a message telling that the package "was 
compiled with optimization - stepping may behave oddly; variables may not be 
available.” And in fact, I cannot evaluate all variables and understand what is 
wrong. I have created a Makevars file in ~/.R/ that contains C=clang -O0 -g but 
it does not seem to change much. What should I do to make sure I can evaluate 
all variables in lldb? I am on a Mac and I wrote C=clang because I read that it 
produced much better error messages but I am happy to use gcc as well if this 
can be a solution.

Edit the file Makeconf in e.g.

 R> file.path(Sys.getenv("R_HOME"), "etc", "Makeconf")
 [1] "/usr/lib/R/etc/Makeconf"
 R> 

It has those settings hardwired from when R itself was compiled for you.  You
probably want to keep a copy of the original file to be able to revert.

Dirk

-- 
http://dirk.eddelbuettel.com | @eddelbuettel | e...@debian.org

__
R-package-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-package-devel