Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Installing nloptr on Linux

Tags:

r

centos

nlopt

I am trying to install the R package nloptr on a CentOS Linux machine that doesn't have internet connection as follows:

install.packages("/home/ravi/nloptr_1.0.4.tar.gz", repos = NULL, type="source")

This command in turn looks for the following file online

http://ab-initio.mit.edu/nlopt/nlopt-2.4.2.tar.gz

However, this fails since there is no internet connection to the machine.

I tried the suggestion from the following stackoverflow post:

trouble with Installing nloptr by locally on Ubuntu

I changed the URL in configure and configure.ac files as follows:

NLOPT_URL="file:///home//ravi//${NLOPT_TGZ}"

However, I get the following error when I try to install the package again:

> install.packages("/home/ravi/nloptr_1.0.4.tar.gz", repos = NULL, type="source")
* installing *source* package 'nloptr' ...
files 'configure', 'configure.ac' have the wrong MD5 checksums
ERROR: 'configure' exists but is not executable -- see the 'R Installation and Administration Manual'
* removing '/opt/vertica/R/library/nloptr'
Warning message:
In install.packages("/home/ravi/nloptr_1.0.4.tar.gz",  :
  installation of package '/home/ravi/nloptr_1.0.4.tar.gz' had non-zero exit status

Can someone guide me on how to install this R package locally?

Update 1

Based on the suggestion from Dirk on installing nlopt first, I followed the instructions given in the following page:

http://ab-initio.mit.edu/wiki/index.php/NLopt_Installation

I installed nlopt as follows :

./configure --enable-shared
make
make install
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/usr/local/lib

When I tried to re-install nloptr in R, it doesn't look for the nlopt link anymore but throws the following error:

Error in dyn.load(file, DLLpath = DLLpath, ...) :
  unable to load shared object '/opt/vertica/R/library/nloptr/libs/nloptr.so':
  /opt/vertica/R/library/nloptr/libs/nloptr.so: undefined symbol:   nlopt_set_maxtime
Error: loading failed
Execution halted
ERROR: loading failed
* removing '/opt/vertica/R/library/nloptr'
Warning message:
In install.packages("/home/ravi/nloptr_1.0.4.tar.gz",  :
  installation of package '/home/ravi/nloptr_1.0.4.tar.gz' had non-zero exit     status

Update 2

As suggested by Dirk, I looked into the ldconfig command and used the following reference:

http://codeyarns.com/2014/01/14/how-to-add-library-directory-to-ldconfig-cache/

I edited the /etc/ld.so.conf file, added the directory /usr/local/lib which contains the shared library and ran the ldconfig command. This added the relevant shared library as shown below:

libnlopt.so.0 (libc6,x86-64) => /usr/local/lib/libnlopt.so.0
libnlopt.so (libc6,x86-64) => /usr/local/lib/libnlopt.so

However, when I tried reinstalling the nloptr package, I still get the same shared object error.

Could someone guide me on the shared library error?

like image 629
Ravi Avatar asked Apr 18 '15 11:04

Ravi


3 Answers

When you say [t]his command in turn looks for the following file online you only get half the story. Together with Jelmer, the maintainer of the actual nloptr package, I modified the package to do the following:

  • look for an install libnlopt library, and, if found, use it
  • if not found fall back to the old behaviour and download the library

So you could simply install nlopt via

 sudo apt-get install libnlopt-dev

(or the equivalent sudo dpkg -i /media/.... pointing to the file from a USB drive etc pp) and then reinstall the nloptr package. It will just work. On my machine:

edd@max:~$ install.r nloptr         ## install.r is in littler
trying URL 'http://cran.rstudio.com/src/contrib/nloptr_1.0.4.tar.gz'
Content type 'application/x-gzip' length 353942 bytes (345 KB)
==================================================
downloaded 345 KB

* installing *source* package ‘nloptr’ ...
** package ‘nloptr’ successfully unpacked and MD5 sums checked
checking for g++... g++
checking whether the C++ compiler works... yes
checking for C++ compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C++ compiler... yes
checking whether g++ accepts -g... yes
checking how to run the C++ preprocessor... g++ -E
checking whether we are using the GNU C++ compiler... (cached) yes
checking whether g++ accepts -g... (cached) yes
checking for pkg-config... yes
configure: Now testing for NLopt header file.
[...]
checking for nlopt.h... yes
configure: Suitable NLopt library found.
configure: creating ./config.status
config.status: creating src/Makevars
** libs
g++ -I/usr/share/R/include -DNDEBUG      -fpic  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -g  -O3 -Wall -pipe -Wno-unused -pedantic  -c dummy.cpp -o dummy.o
gcc -I/usr/share/R/include -DNDEBUG      -fpic  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -g  -O3 -Wall -pipe -pedantic -std=gnu99 -c nloptr.c -o nloptr.o
g++ -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions -Wl,-z,relro -o nloptr.so dummy.o nloptr.o -lnlopt -lm -L/usr/lib/R/lib -lR
installing to /usr/local/lib/R/site-library/nloptr/libs
** R
** inst
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded
* DONE (nloptr)

The downloaded source packages are in
        ‘/tmp/downloaded_packages’
edd@max:~$ 

Note how it compiled only two files from the actual R packages having found the nlopt installation.

like image 112
Dirk Eddelbuettel Avatar answered Oct 22 '22 05:10

Dirk Eddelbuettel


I had exactly the same problem, on a production machine without direct Internet access, with Red Hat Enterprise Linux Server release 6.6 (Santiago). The fixups proposed above did not work: when installing the nlopt library on the system, the subsequent attempt to install nloptr fail with the "nlopt_set_maxtime" error. I tried to fiddle with compilation options for nlopt, to no avail. I even reproduced the problem on a Ubuntu machine with Internet connection: I uninstalled nloptr, installed nlopt on the system and then the nloptr installation failed.

At last I solved the issue taking the following steps:

  1. Un-install nlopt from the operating system (make sure that it is thoroughly removed).
  2. Manually download nlopt-2.4.2.tar.gz and copy it to /tmp/
  3. Manually download nloptr_1.0.4.tar.gz to a work directory and unpack it; this creates the directory "nloptr/".
  4. Edit "nloptr/configure", comment out the row

    $("${R_HOME}/bin/Rscript" --vanilla -e "download.file(url='${NLOPT_URL}', destfile='${NLOPT_TGZ}')")

    and insert a new row:

    $("${R_HOME}/bin/Rscript" --vanilla -e "file.copy(from='/tmp/nlopt-2.4.2.tar.gz', to='${NLOPT_TGZ}')")

  5. Install with "R CMD INSTALL nloptr".

like image 13
renato vitolo Avatar answered Oct 22 '22 05:10

renato vitolo


I had a similar problem on Ubuntu. In addition to installing nlopt-dev as Dirk answered, I also had to install pkg-config:

sudo apt-get install pkg-config

Hope this helps.

like image 13
Ole Høst Avatar answered Oct 22 '22 05:10

Ole Høst