在 Linux 上安装 nloptr [英] Installing nloptr on Linux

查看:56
本文介绍了在 Linux 上安装 nloptr的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在没有 Internet 连接的 CentOS Linux 机器上安装 R 包 nloptr,如下所示:

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.

我尝试了以下 stackoverflow 帖子中的建议:

I tried the suggestion from the following stackoverflow post:

在 Ubuntu 上本地安装 nloptr 遇到问题

我将 configure 和 configure.ac 文件中的 URL 更改如下:

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

有人可以指导我如何在本地安装这个 R 包吗?

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

更新 1

根据 Dirk 关于先安装 nlopt 的建议,我按照以下页面中的说明进行操作:

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

我安装 nlopt 如下:

I installed nlopt as follows :

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

当我尝试在 R 中重新安装 nloptr 时,它不再寻找 nlopt 链接,而是抛出以下错误:

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

更新 2

按照 Dirk 的建议,我查看了 ldconfig 命令并使用了以下参考:

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/

我编辑了/etc/ld.so.conf 文件,添加了包含共享库的目录/usr/local/lib 并运行了 ldconfig 命令.这添加了相关的共享库,如下所示:

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

但是,当我尝试重新安装 nloptr 包时,我仍然收到相同的共享对象错误.

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?

推荐答案

当你说[t]他的命令反过来在网上查找以下文件你只得到了一半.我与实际 nloptr 包的维护者 Jelmer 一起修改了该包以执行以下操作:

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:

  • 查找安装 libnlopt 库,如果找到,请使用它
  • 如果未找到,则返回旧行为并下载库

所以你可以简单地通过安装 nlopt

So you could simply install nlopt via

 sudo apt-get install libnlopt-dev

(或等效的 sudo dpkg -i/media/.... 从USB 驱动器等 pp),然后重新安装 nloptr 包.它会起作用的.在我的机器上:

(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:~$ 

注意它是如何从找到 nlopt 安装的实际 R 包中只编译两个文件的.

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

这篇关于在 Linux 上安装 nloptr的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆