30

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?

Community
  • 1
  • 1
Ravi
  • 3,223
  • 7
  • 37
  • 49

8 Answers8

34

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.

Dirk Eddelbuettel
  • 360,940
  • 56
  • 644
  • 725
  • Hi Dirk, I neither have apt-get or dpkg installed in my machine. Is there any other way to go about it? – Ravi Apr 18 '15 at 12:03
  • Sure. Then your question is completely, or you are totally confused, as you are *unlikely to be on a Ubuntu machine*. Installing nlopt will still help you: the behaviour of *using nlopt if found* is property of the CRAN package you are trying to install. – Dirk Eddelbuettel Apr 18 '15 at 12:05
  • Apologies. I am on a CentOS distribution. Confused it with my other machine. – Ravi Apr 18 '15 at 12:11
  • Dirk, I tried installing a version of nlopt and again retried installing nloptr. I still get a share object error. I have updated my OP with the latest output. Is there a way to fix the shared object error? – Ravi Apr 18 '15 at 14:01
  • You appear to have installed a shared library in a non-standard location. Search StackOverflow (or via Google) for `ldconfig` and `ld.so.conf`. You are now dealing with how to use a locally installed library from a non-standard path. – Dirk Eddelbuettel Apr 18 '15 at 14:36
  • Dirk, I tried the ldconfig command and have posted an Update 2. I still get the same shared object error when I install the R package. – Ravi Apr 18 '15 at 15:22
  • Same problem here, also on a CentOS machine - except that I do have an internet connection, so I don't need to install from local source. I tried all the fixes above - separately, combined, and all of them at once -, but no good. I can install NLOPT without problems - `yum install nlopt` works fine (`./configure`, `make`, etc, works too). But no matter what I do I get `undefined symbol: nlopt_set_maxtime` when trying to install nloptr (be it with `install.packages("nloptr")` or with `R CMD INSTALL nloptr`). I've been at it for 8 hours now. – Parzival Mar 24 '16 at 13:44
  • 1
    If there is something called nlopt-dev, you need it too. _Running_ against nlopt is not the same as _building and linking_ against it. – Dirk Eddelbuettel Mar 24 '16 at 14:07
13

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

renato vitolo
  • 1,744
  • 11
  • 16
  • Hi.. Even after making the above change in the configure script of nloptr and recreating the tar.gz, I get the same error "unable to load shared object '/usr/lib64/RRO-8.0.2/R-3.1.2/lib64/R/library/nloptr/libs/nloptr.so':" – myloginid Jun 17 '15 at 06:43
  • I did not recreate the .tar.gz: I installed straight from the directory "nloptr/" where I had unpacked the original .tar.gz and then modified "nloptr/configure". Not sure that this might make a difference though... – renato vitolo Jun 18 '15 at 08:46
  • Agree. But just the same that dosent work too. I did that because R usually requires us to provide a .tar.gz and I was not sure if it would work without that. My Infra team does not allow direct connection to the Internet. – myloginid Jun 19 '15 at 04:53
  • I was wondering though: have you completely dis-installed the manually installed version of nloptr and any other version before trying the above process? With a "clean" machine, I could not see any reason for failure... – renato vitolo Jun 22 '15 at 16:04
  • In case anyone still face any issues while installing then extract a fresh copy of 'nloptr' folder from nloptr_1.0.4.tar.gz and then follow above process. It should work after that. – Arpit Gupta Mar 03 '16 at 05:15
  • 1
    This worked for me as long as I did `make uninstall` in the extracted `nlopt/` folder. After removing nlopt completely I was able to run the above and get it working. – Mark Nielsen Aug 25 '16 at 19:26
  • @MarkNielsen Thank you, I modified my solution, adding the preliminary step of completely removing nlopt from the system before attempting a fresh install. – renato vitolo Aug 25 '16 at 19:44
  • I tried the solution above, but for me it is still not working. I am on a openSuse Leap and the `R CMD INSTALL nloptr` fails with `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC` then `/usr/local/lib64/libnlopt.a: error adding symbols: Bad value` – mRcSchwering Dec 12 '16 at 15:01
13

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.

Community
  • 1
  • 1
Ole Høst
  • 131
  • 1
  • 3
9

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.

Xiongbing Jin
  • 11,779
  • 3
  • 47
  • 41
  • thanks...the problem is that you still get v. 2.4 ... v. >= 2.7 is required for packages like factoextra ... any idea on how to get more recent v. ? – jjrr Mar 03 '22 at 08:43
3

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:

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

0

if you are using AWS Linux the below should help

yum --enablerepo=epel install NLopt-devel -y
LJT
  • 1,250
  • 3
  • 20
  • 25
0

I just solved this on my server with following two steps:

  1. Install libnlopt-dev and nlopt with
sudo apt-get install libnlopt-dev
pip install nlopt
  1. Use sudo R to launch R and type:
withr::with_makevars(c(PKG_LIBS='-lnlopt'),install.packages('nloptr'),assignment='+=')
Deku
  • 81
  • 1
  • 3
  • Why is it necessary to do this with `sudo`? – flies Mar 03 '21 at 16:17
  • Maybe not necessary, I used `sudo R` to install the package `png` last time. In that case, I couldn't install `png` without `sudo`. – Deku Mar 04 '21 at 05:27
  • IME, installing libraries as super-user can lead to confusion and possibly dependency hell. `install.packages` when run from the console executes as user, so, unlless you're scrupulous about never installing from a normal "working sesssion", you have a confusing web of some libraries belonging to super user and some not. What happens when user installs a new library requiring an updated version of a library installed by super-user? – flies Mar 05 '21 at 21:14
-2

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