0

I have installed the R package "Rglpk" manually in following manner as root user on ec2-instance of Redhat 7:

mkdir -p GLPK
wget http://ftp.gnu.org/gnu/glpk/glpk-4.47.tar.gz
tar xvf glpk-4.47.tar.gz
cd glpk-4.47
./configure --prefix=/home/ec2-user/GLPK
make
make install
cd ..

wget https://cran.r-project.org/src/contrib/Rglpk_0.6-3.tar.gz
tar xvf Rglpk_0.6-3.tar.gz
mv glpk-4.47 /home/ec2-user/Rglpk/src/GLPK
export LD_LIBRARY_PATH=/home/ec2-user/GLPK/lib
export LIBRARY_PATH=/home/ec2-user/GLPK/lib
export CPATH=/home/ec2-user/GLPK/include
R CMD INSTALL Rglpk

The issue is when i am calling this library in R cli with root as user,it works fine but when i switch to my user i.e. ec2-user and once call this library in R cli ,it starts giving following error for all users,even for root.

library("Rglpk")
Loading required package: slam
Error: package or namespace load failed for ‘Rglpk’ in dyn.load(file, DLLpath = DLLpath, ...):
 unable to load shared object '/usr/lib64/R/library/Rglpk/libs/Rglpk.so':
  libglpk.so.0: cannot open shared object file: No such file or directory

The file is still present in that location:

0(ec2-user@resuerdsfdfsfdn02 [~])$ cd /usr/lib64/R/library/Rglpk/libs/
0(ec2-user@resuerdsfdfsfdn02 [/usr/lib64/R/library/Rglpk/libs])$ ls
Rglpk.so*
Arshanvit
  • 417
  • 1
  • 7
  • 28
  • 1
    Autotools does not properly configure the program it is building. You need to properly configure the library. Your `LDFLAGS` should include `-Wl,-R,/home/ec2-user/GLPK/lib -Wl,--enable-new-dtags`. Then you won't need hacks like `LD_LIBRARY_PATH` that have plagued Linux for the last 20 years or so. – jww Jul 18 '18 at 06:58
  • @jww,i am quite new to programming paradigm of R and inherent language,will you kindly explain in detail what these flags are and supported materials.Much Appreciated – Arshanvit Jul 18 '18 at 07:01

3 Answers3

1

The problem is that libglpk.so.0 isn't in the path in the RStudio server's R environment, even though it's in the R environment that you call from your terminal session. It's less than ideal, but a solution is to put the following line in your .Rprofile file:

dyn.load("/home/ec2-user/GLPK/lib/libglpk.so.0")

This will load the shared library from the path you've specified, instead of having R infer the path from your environment. If your RStudio-server is being run from a different account than the default ec2-user profile on your instance, just replace 'ec2-user' in the above path with whatever username you're using. Once that's done, you should be able to call 'Rglpk' from your RStudio-server session.

Dr. Arun
  • 176
  • 6
0

The main issue lies that whenever Rglpk or any other R packages are called,they are not able to find files such as libglpk.so.0 as the environment variables were executed locally which points to location of it till the user cli exists.Thus set the environment variables system-wide so that this library can access irrespective of users:

1)Edit /etc/bashrc

2)Place the following variables in it at last:

export LD_LIBRARY_PATH=/home/ec2-user/GLPK/lib
export LIBRARY_PATH=/home/ec2-user/GLPK/lib
export CPATH=/home/ec2-user/GLPK/include

3)Reload the file:

source /etc/bashrc
Arshanvit
  • 417
  • 1
  • 7
  • 28
0

From my experience dyn.load loads the package but is not enough for using functions. So I use:

dyn.load("/home/ec2-user/GLPK/lib/libglpk.so.40") 
Sys.getenv("LD_LIBRARY_PATH")
Sys.setenv(LD_LIBRARY_PATH=paste0(Sys.getenv("LD_LIBRARY_PATH"), ":", "/home/ec2-user/GLPK/lib"))

For INSTALL I had to use:

export PKG_CFLAGS='-I/home/user/GLPK/include'
export PKG_LIBS='-L/home/user/GLPK/lib'
Ferroao
  • 3,042
  • 28
  • 53