GLPK: No such file or directory error when trying to install R package - r

I am trying to install sparkTable in R 3.1.0 which depends on Rglpk. I manually installed GPLK on the system and added the libs folder to LD_LIBRARY_PATH before going into R for the install.packages("sparkTable") procedure. I get this error during the installation process. Any ideas?
* installing *source* package ‘Rglpk’ ...
** package ‘Rglpk’ successfully unpacked and MD5 sums checked
** libs
/bin/sh: line 0: cd: GLPK: No such file or directory
make: *** [GLPK.ts] Error 1
ERROR: compilation failed for package ‘Rglpk’
* removing ‘/opt/R/R-3.1.0/lib64/R/library/Rglpk’
ERROR: dependency ‘Rglpk’ is not available for package ‘sparkTable’
* removing ‘/opt/R/R-3.1.0/lib64/R/library/sparkTable’

sudo apt-get install libglpk-dev
did the trick for me.

I had this problem and took a good bit of digging in the package to understand what was happening. If Rgplk can't compile its test program when installing, it does something weird, including this bizarre cd to nowhere. Assuming glpk-devel is installed, the reason it can't compile the test program is that it can't find the gplk header as it is in a non-standard directory.
Just set the environment variable CPATH=/usr/include/glpk
and the test program will compile, allowing the package install to proceed normally.

I had this problem too. The following steps solved this issue for me. My current setup:
OS: Scientifc Linux version 6.5 (on a High Performance Cluster Server)
local user, no root access.
GLPK was not installed
Install GLPK in a local directory:
wget http://ftp.gnu.org/gnu/glpk/glpk-4.54.tar.gz
tar xfzv glpk-4.54.tar.gz
mkdir GLPK
cd glpk-4.54
./configure --prefix=/home/<username>/GLPK
make
make install
Install Rglpk (0.6-3):
cd ~
wget http://cran.r-project.org/src/contrib/Rglpk_0.6-3.tar.gz
export LIBRARY_PATH=/home/<username>/GLPK/lib
R CMD INSTALL Rglpk_0.6-3.tar.gz

I landed on this page, because I could not update igraph under Windows 10/11, since igraph also requires glpk as per OP. Specifically:
igraph_glpk_support.h:36:10: fatal error: glpk.h: No such file or
directory #include <glpk.h>
^~~~~~~~ compilation terminated. make: *** [C:/PROGRA~1/R/R-4.1.1/etc/x64/Makeconf:238: feedback_arc_set.o] Error
1 ERROR: compilation failed for package 'igraph'
removing 'C:/Users/xxx/Documents/R/win-library/4.1/igraph'
restoring previous 'C:/Users/xxx/Documents/R/win-library/4.1/igraph' Warning
in install.packages : installation of package ‘igraph’ had non-zero
exit status
I am under Windows 11 (but would be same for Windows 10).
Simple resolution is suggested here:
start Rtools Bash (found in all apps, Rtools 4.0 in the Windows menu)
Run pacman -S mingw-w64-x86_64-glpk and confirm with yes (y)
Run pacman -S mingw-w64-x86_64-libxml2 and confirm with yes (y)
Updating igraph in Rstudio now leads to a clean
DONE (igraph)
(there is no need to install anything, add any path, etc... just the above 4 steps)

In ubuntu 14.04, all above doesn't work. the following however works, without the need of installing libglpk-dev using apt-get.
download the glpk package from gnu and extract it:
wget http://ftp.gnu.org/gnu/glpk/glpk-4.55.tar.gz
tar xvf glpk-4.55.tar.gz
make a GLPK directory in your local path:
mkdir ~/GLPK
configure within glpk:
cd glpk-4.55
./configure --prefix=$HOME/GLPK
cd ..
export LD_LIBRARY_PATH=$HOME/GLPK/lib
export LIBRARY_PATH=$HOME/GLPK/lib
export CPATH=$HOME/GLPK/include
download the Rglpk package from cran and extract it:
wget http://cran.r-project.org/src/contrib/Rglpk_0.6-0.tar.gz
tar xvf Rglpk_0.6_0.tar.gz
move the glpk directory into Rglpk/src and rename it to GLPK:
mv glpk-4.55 Rglpk/src/GLPK
now you can install:
R CMD INSTALL Rglpk
now a bit of explanation of what's going on. The "src/Makevars.in" file in the Rglpk package contains a line of code to enter a non-existing directory 'GLPK' within the src/ folder:
(line 11 of Makevars.in)
GLPK.ts:
#(cd GLPK && make)
touch $#
this is where the problem arises. obviously the code is trying to build glpk within that directory for some unknown reasons. and the solution above is achieved simply by moving the downloaded (and configured) glpk directory there...

If you're on a Debian-based Linux distribution, run this to install GLTK:
sudo apt install libglpk-dev
If you're on MacOS, run this to install GLTK:
brew install gltk
Finally, install the R library:
install.packages("Rglpk")

On Centos, have sudo rights. None of the above worked, but had to install GLPK in /usr/local as suggested in this SO answer. Been trying to install it for about 3 hours fml

You must install glpk dependency first.
On macOS (via homebrew):
brew install glpk
or in RStudio (via homebrew):
system("brew install glpk")

It worked for me when I combined the answers from Simón Ramírez Amaya and shadowleaves:
wget http://ftp.gnu.org/gnu/glpk/glpk-4.54.tar.gz
tar xfzv glpk-4.54.tar.gz
mkdir GLPK
cd glpk-4.54
./configure --prefix=$HOME/GLPK
make
make install
cd ..
export LD_LIBRARY_PATH=$HOME/GLPK/lib
export LIBRARY_PATH=$HOME/GLPK/lib
export CPATH=$HOME/GLPK/include
wget https://cran.r-project.org/src/contrib/Rglpk_0.6-4.tar.gz
R CMD INSTALL Rglpk_0.6-4.tar.gz
To load the library
dyn.load(file.path(Sys.getenv("HOME"), "GLPK", "lib", "libglpk.so"))
library(Rglpk)

The answer of Zhiying Cui is right, however, if your script has some special codes, such as foreach for parallel computing, it may raise an error.
A better way is as fellow
If your os is Centos, try
yum install glpk-devel
then just go to R or Rstudio server and
install.packages("Rglpk")

Related

How to install Rmpfr on Ubuntu 18.04?

After install.packages("Rmpfr") I'm getting this error
configure: error: Header file mpfr.h not found; maybe use
--with-mpfr-include=INCLUDE_PATH
ERROR: configuration failed for package ‘Rmpfr’
I typed the suggestion --with-mpfr-include=INCLUDE_PATH into the terminal w/o success.
Look here: https://github.com/cran/Rmpfr
You first have to install the dependend libraries.
sudo apt-get install libmpfr-dev
sudo su - -c "R -e \"install.packages('Rmpfr', repos='http://cran.rstudio.com/')\""
It is also a better solution to install the R-Packages from the console, not inside R, since every user on the machine will have access to the package then. Otherwise it will just be in your personal library.

Rserve : ld: library not found for -lssl

I am getting an error while trying to install Rserve 1.8.6. I can successfully install 1.7.3 from CRAN. This is on Mac OS High Sierra.
ld: library not found for -lssl
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[1]: *** [forward] Error 1
make: *** [all] Error 2
ERROR: compilation failed for package ‘Rserve’
* removing ‘/Library/Frameworks/R.framework/Versions/3.5/Resources/library/Rserve’
* restoring previous ‘/Library/Frameworks/R.framework/Versions/3.5/Resources/library/Rserve’
The downloaded source packages are in
‘/private/var/folders/v7/hyxrfmk94p1_03gdrm27fnxncy3vq1/T/RtmpFHKNMe/downloaded_packages’
This worked for me (MacOS):
In terminal:
brew install openssl
export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl/lib/
I'm running Mac OS 10.15 Catalina, I've spent 2 days trying to fix this same problem, scouring the internet for help. I finally managed it by cobbling together solutions from a few different sources.
The key thing I was missing was that Mac OS ships with its own version of openssl which it thinks is superior to anything else you can find. It is wrong. What you need to do is go and download the latest version of openssl, install that, then export THAT library to your library path variable. Here are the steps I took with openssl 1.1.1:
Get the version number for the latest version of openssl from the source (https://www.openssl.org/source/) and then manually install it directly where it's supposed to go:
cd /usr/local/src
If you're getting "No such file or directory", make it:
cd /usr/local && mkdir src && cd src
Download openssl using curl (shown) or using the link above to the source code (make sure you put the file in the directory you just made in the previous step):
curl --remote-name https://www.openssl.org/source/openssl-1.1.1f.tar.gz
Extract and cd in:
tar -xzvf openssl-1.1.1f.tar.gz
cd openssl-1.1.1f
Compile and install (these are the 64 bit Mac OS instructions. Refer to the openssl documentation for 32 bit and other OS instructions):
./Configure darwin64-x86_64-cc shared enable-ec_nistp_64_gcc_128 no-ssl2 no-ssl3 no-comp --openssldir=/usr/local/ssl/macos-x86_64
make depend
sudo make install
This created a new openssl folder so when you export the library path you have to feed it the right openssl folder:
export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl#1.1/lib/
Hope that helps you if you haven't figured it out yet, and anyone else in the future who is ready to chuck their computer across the room, like I was.

OSX Installing Rsymphony - linking headers and libs

symphony is correctly installed and tested in terminal. R complains about missing header and libraries when trying to install Rsymphony from source. Any pointers are HIGHLY appreciated. thank you!
symphony installation directory: /Users/timo/Applications/symphony/
R install command:
install.packages("Rsymphony", configure.args="--with-SYMPHONY-include=/Users/timo/Applications/symphony/include/ --with-SYMPHONY-lib=/Users/timo/Applications/symphony/lib",type="source")
results in :
* installing *source* package ‘Rsymphony’
** package ‘Rsymphony’ successfully unpacked and MD5 sums checked
Cannot find SYMPHONY libraries and headers.
See <https://projects.coin-or.org/SYMPHONY>.ERROR: configuration failed for package ‘Rsymphony’* removing ‘/Library/Frameworks/R.framework/Versions/3.2/Resources/library/Rsymphony’* restoring previous‘/Library/Frameworks/R.framework/Versions/3.2/Resources/library/Rsymphony’
I also struggled to get Rsymphony installed, but finally got it working after many hours of messing around. Here's what I did, hopefully it'll save others some time. This works on Mac OS El Capitan (10.11) and R 3.3.0.
First, install the homebrew package manager if you don't already have it:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Next install SYMPHONY with homewbrew. I found this to be the best approach because it puts everything in the right place:
brew tap coin-or-tools/coinor
brew install symphony
Now install pkg-config, a tool for querying installed libraries for when compiling software source code. Not sure if this is strictly necessary, but pkg-config is used in the configuration script for Rsymphony:
brew install pkg-config
At this point Rsymphony should now be able to find the necessary SYMPHONY libraries, however, I still got the following compiler error:
ld: warning: directory not found for option '-L/usr/local/lib/gcc/x86_64-apple-darwin13.0.0/4.8.2'
ld: library not found for -lgfortran
Apparently it has something to do with needing a different version of the fortran compiler. This helpful post with instructions for getting the correct compiler saved me. Run the following commands:
curl -O http://r.research.att.com/libs/gfortran-4.8.2-darwin13.tar.bz2
sudo tar fvxz gfortran-4.8.2-darwin13.tar.bz2 -C /
Now, finally, you should be able to install Rsymphony with:
install.packages("Rsymphony", type = "source")
SOLUTION:
I have found the solution in this link (...I got RSymphony to install, but it involved some hacking ...)
Installing RSymphony using RStudio on macOS
I had also this issue: ..no checking for COIN-OR package CoinUtils... and it was solved by "export PKG_CONFIG=/usr/local/bin/pkg-config; export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig/"

gcc error when installing Statnet package

Installing statnet on mac 10.10.3 with R 3.2.x (RStudio 0.99.441).
ld: warning: directory not found for option '-L/usr/local/lib/gcc/x86_64-apple-darwin13.0.0/4.8.2'
ld: library not found for -lgfortran
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [latentnet.so] Error 1
ERROR: compilation failed for package ‘latentnet’
* removing ‘/Library/Frameworks/R.framework/Versions/3.2/Resources/library/latentnet’
Warning in install.packages :
installation of package ‘latentnet’ had non-zero exit status
ERROR: dependency ‘latentnet’ is not available for package ‘statnet’
* removing ‘/Library/Frameworks/R.framework/Versions/3.2/Resources/library/statnet’
Warning in install.packages :
installation of package ‘statnet’ had non-zero exit status
I tried updating XCode/Command Line Tools. Also tried not installing dependencies. I have been able to install other packages, such as ergm and sna.
It looks like the install is looking for the GCC folder and not finding it.
whereis gcc
reveals that my gcc is in /usr/bin/gcc
It looks like the install is looking for it in /usr/local/lib/gcc/
Is there a way to fix this?
This is a compilation error that you only get if you are trying to install packages from source, or when a package requires a library to be compiled from source. Normally, if you don’t use the latest version of R, you can install statnet from binary and thus R won’t have to compile the source package.
The version you are mentioning at the beginning of your message (0.99.441) is the version of your R-Studio, and not R. The version of your R is 3.2.x (Hence its address in the Library folder: /Library/Frameworks/R.framework/Versions/3.2/Resources…). Before trying to fix the compilation error you may want to try to roll back your R to a version like 3.1.2 or 3.1.3 on which you can probably download and install statnet in binary format.
For the compiler, my guess is that even if you fix the address of your gcc with a symlink, you will still get an error about gfortran or the version of gcc. Once I solved this issue by installing R and the right version of gcc through Homebrew, but right now I don’t have the possibility to try the solution and tell you exactly how.
My experience (on Yosemite) is that if you use 3.1.2 or 3.1.3, even if there is need for compilation, the error with gcc won’t occur.
sudo mkdir /usr/bin/lib && sudo ln -s /usr/bin/gcc /usr/bin/lib/gcc
Creates a new directory in /usr/bin called `lib' and creates a symbolic link to gcc in that new directory.
If that doesn't fix the error, you can undo it with:
sudo rm -i /usr/bin/lib/gcc && sudo rm -id /usr/bin/lib

how to install R packages "RNetCDF" and "ncdf" on Ubuntu?

I would like to use the R packages RNetCDF and ncdf in Ubuntu.
When I try install.packages('RNetCDF') or install.packages('ncdf'), I get similar errors:
...
ncdf.c:3:20: fatal error: netcdf.h: No such file or directory
compilation terminated.
make: *** [ncdf.o] Error 1
ERROR: compilation failed for package ‘ncdf’
...
Warning message:
In install.packages("ncdf") :
installation of package ‘ncdf’ had non-zero exit status
The packages libnetcdf6 and netcdf-bin from the Ubuntu repository are installed. Do I need to do something else?
You need to install the -dev of those packages to get the headers that are required to compile the package. In this case, you need libnetcdf-dev, udunits-bin and libudunits2-dev
In my case, libudunits2-dev package was needed.
sudo apt-get install libudunits2-dev
Since I installed NetCDF from source, I had to manually specify the locations of lib and include folders
install.packages("/home/user/Downloads/RNetCDF_1.6.1-2.tar.gz",
repos = NULL,
type="source",
dependencies=FALSE,
configure.args="--with-netcdf-include=/usr/local/netcdf-4.2.1-build/include --with-netcdf-lib=/usr/local/netcdf-4.2.1-build/lib")
Just to clarify, since your initial issue is in R, and the fix is applied outside of R. I initially was trying to do
install.packages("libnetcdf-dev"), which didn't work.
instead, from outside of R: sudo apt-get install libnetcdf-dev
That fixed it for me.
In Ubuntu 20.04 LTS one can install the ncdf4 package (which supersedes ncdf), including all dependencies, with the bash command sudo apt install r-cran-ncdf4. Similarly for RNetCDF you can use sudo apt install r-cran-rnetcdf.

Resources