首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >在Linux上安装nloptr

在Linux上安装nloptr
EN

Stack Overflow用户
提问于 2015-04-18 19:44:20
回答 8查看 19K关注 0票数 29

我正在尝试将R包nloptr安装在一台没有互联网连接的CentOS Linux机器上,如下所示:

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

此命令依次在线查找以下文件

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

但是,由于没有到机器的互联网连接,此操作将失败。

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

trouble with Installing nloptr by locally on Ubuntu

我在配置和configure.ac文件中更改了URL,如下所示:

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

但是,当我再次尝试安装该软件包时,出现以下错误:

> 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包?

更新1

根据Dirk关于首先安装nlopt的建议,我遵循了以下页面中的说明:

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

我按如下方式安装了nlopt:

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

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

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命令并使用了以下引用:

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

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

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

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

有人能在共享库错误上给我指点一下吗?

EN

回答 8

Stack Overflow用户

回答已采纳

发布于 2015-04-18 19:55:54

当您说这个命令反过来在线查找下面的文件时,您只得到了一半的信息。与实际nloptr包的维护者Jelmer一起,我修改了包以执行以下操作:

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

因此您可以通过以下方式安装nlopt

 sudo apt-get install libnlopt-dev

(或从U盘指向文件的等效sudo dpkg -i /media/....等pp),然后重新安装nloptr包。它会正常工作的。在我的机器上:

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包中仅编译了两个文件。

票数 32
EN

Stack Overflow用户

发布于 2015-05-05 15:58:40

我遇到了完全相同的问题,在一台没有直接Internet访问的生产机器上,使用Red Hat Enterprise Linux Server release 6.6 (圣地亚哥)。上面提出的修复方法不起作用:当在系统上安装nlopt库时,随后尝试安装nloptr失败,并出现"nlopt_set_maxtime“错误。我试图修改nlopt的编译选项,但无济于事。我甚至在一台连接了互联网的Ubuntu机器上重现了这个问题:我卸载了nloptr,在系统上安装了nlopt,然后nloptr安装失败。

最后,我通过以下步骤解决了这个问题:

  1. 从操作系统卸载nlopt (确保彻底下载nlopt-2.4.2.tar.gz并将其复制到/tmp/
  2. 手动将nloptr_1.0.4.tar.gz下载到工作目录并解压缩;这将创建目录"nloptr/".
  3. Edit“nloptr/nloptr_1.0.4.tar.gz”,注释掉该行

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

并插入新行:

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

  • Install with "R CMD INSTALL nloptr”。
票数 13
EN

Stack Overflow用户

发布于 2016-09-20 23:15:00

我在Ubuntu上也遇到过类似的问题。除了以Dirk answered身份安装nlopt-dev之外,我还必须安装pkg-config:

sudo apt-get install pkg-config

希望这能有所帮助。

票数 13
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29716857

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档