ropensci / magick

Magic, madness, heaven, sin
https://docs.ropensci.org/magick
Other
456 stars 63 forks source link

How to set rpath in the magick library #233

Open bzfbmsch opened 4 years ago

bzfbmsch commented 4 years ago

Hi, I am trying to install magick with R 3.6.2 on a compute center. No access to the system, but full controll over my environment maintained by "environmental modules". ImageMagick is at a non-default place, the binaries are in PATH and pkg-config finds it. The installation goes almost through, I see the correct include path in the compiler output, but finally the library cannot be loaded - libMagick++-7.Q16HDRI.so.4 is not found. This failure is to be expected. The configure procedure for magick takes all setting from the original R installation procedure but does not add the path to libMagick++-7.Q16HDRI.so.4 to the rpath set in libmagic.so.

A workaround would be to define LD_LIBRARY_PATH. Indeed, this gives a working magick package. However, I am not allowed to set LD_LIBRARY_PATH in the module files build for the public. Please do not argue about that here, it has reasons.

Alternatively, install.packages https://www.rdocumentation.org/packages/utils/versions/3.6.2/topics/install.packages has parameters configure.args and configure.vars to send more information to configure. However, it seems that the magick package ignores all values completely.

So my question is, if there are any means to extend the RPATH written into libmagick.so can be extended with the path to libMagick++-7.Q16HDRI.so.

Many thanks, Martin Schmidt

jeroen commented 4 years ago

I don't think it's possible to hardcode the path to libMagick++-7.Q16HDRI.so in libmagick.so.

Perhaps you can try setting R_LD_LIBRARY_PATH for example in your ~/.Renviron file, see also the r administration manual

bzfbmsch commented 4 years ago

Thanks Jeroen. There is no hardcoding needed. All I need to do is to set the compiler option -Wl,-rpath=. This sends the information to the linker and that's it. Indeed, this option is used but only for the path's defined in the original R installation. However, how to send an additional compiler option through the arguments of "install.packages", configure.args and configure.vars? It seems that additional CFLAGS and CXXFLAGS are ignored. Does the magick package care, if they are defined? I could reinstall R and add the path to ImageMagick to the rpath in the very beginning. But this inflates the RPATH of all R-packages. And then comes the next package ..... Thanks for the hint R_LD_LIBRARY_PATH.

jeroen commented 4 years ago

The package configure script is very simple, currently there is no way to pass custom flags to the linker. If you think it is important and want to do a PR we could perhaps add it.

But I'm not sure if it's a good idea, the common way to do this by setting LD_LIBRARY_PATH or R_LD_LIBRARY_PATH the location of your shared libraries.

However, I am not allowed to set LD_LIBRARY_PATH in the module files build for the public.

I don't understand, are you building the magick R package for the public but still trying to link a local shared library of imagemagick?

bzfbmsch commented 4 years ago

Good morning. I am installing for all users in our compute center. The binary will be used there, not somewhere else. We have a list of all requested packages and install them as default with a new R version. This saves us from giving support for all the personal builds.

We have a new OS (centos7). magick does not link with ImageMagick from this linux-distribution. It is related to incompatible compiler versions. There is a closed thread in this githup area around this problem. So I build my own ImageMagick, now in a non-default place. There are just no means to tell magick correctly, where ImageMagick is now.

I think a PR should not done now, but may be, when work and testing is done on the package anyway in future, a path should be opened to add config.vars and config.args over install.packages. Alternatively, the path to the ImageMagick libraries may be added by default to RPATH in libmagick. I would be happy with this solution, but others may be missing the advantages of LD_LIBRARY_PATH in this case.

All the best! Martin

jeroen commented 4 years ago

Couldn't you just use the gcc and imagemagick from CentOS to build the magick package? I go through a lot of effort to make sure everything works on all operating systems. If you use the default gcc from centos, or alternatively gcc from redhat developer tools, you should be able against the standard imagemagick package on CentOS 7.

jeroen commented 4 years ago

Here is am example docker image we use to build R packages on CentOS + RDT: https://github.com/r-hub/rhub-linux-builders/blob/master/centos6-epel-rdt/Dockerfile

dmi3kno commented 4 years ago

I am not sure if this is directly helpful, but I want to just leave this SO link here.

jan-glx commented 3 years ago

I just needed someone to tell me to add <path to imagemagic>/lib/pkgconfig to PKG_CONFIG_PATH, so I am leaving that here (not sure if that solves OP's problem).