Installing nloptr on Linux

梦想的初衷 提交于 2019-12-03 05:37:58

问题


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?


回答1:


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.




回答2:


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".




回答3:


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.




回答4:


If you are on CentOS (and have internet access, but the nlopt server is not reachable), you can install nlopt first using

yum install nlopt nlopt-devel

Then you can install nloptr normally.




回答5:


I had the same issue setting up nloptr on my RHEL 7.2 instance. For those using RHEL you can do the following: Download & install the following RPMS in the same order:

  • NLopt-2.4.2-2.el7.x86_64.rpm- https://pkgs.org/centos-7/epel-x86_64/NLopt-2.4.2-2.el7.x86_64.rpm.html

  • NLopt-devel-2.4.2-2.el7.x86_64.rpm - https://pkgs.org/centos-7/epel-x86_64/NLopt-devel-2.4.2-2.el7.x86_64.rpm.htm

Please note that these RPMs may need additional dependencies to be installed based on your system configuration.

Post this you can install nloptr directly using the install.packages utility or download source from CRAN and install from source as suggested in earlier responses.

Hope this helps!

Kiran




回答6:


if you are using AWS Linux the below should help

yum --enablerepo=epel install NLopt-devel -y



回答7:


I think I have the same problem as you and I am using CentOS 6.5 Remove nlopt and install nloptr with install.packages() in R, a nlopt will be installed automatically.

I removed installed nlopt with the following command in the unzipped nlopt folder.

make uninstall 

If you had tried to use epel repository in CentOS and had installed nlopt with yum, try:

yum remove nlopt

After removing existed nlopt, I am able to install nloptr with

install.packages("nloptr")


来源:https://stackoverflow.com/questions/29716857/installing-nloptr-on-linux

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!