在Linux上安装nloptr - 致命错误:没有找到nlopt.h文件或目录。

10

在Linux(Ubuntu 14.04.4 LTS)上安装nloptr包时,遇到了困难,希望得到帮助。我查看了许多问题,但没有找到解决办法。

由于nloptr安装出现非零退出状态,我无法在R(版本3.3.1 / Rstudio版本0.99.902)中安装lme4软件包。当我尝试时:

    install.package("nloptr") 

我得到了以下内容:

Installing package into ‘/home/rd14/R/x86_64-pc-linux-gnu-library/3.3’
(as ‘lib’ is unspecified)
trying URL 'https://cran.rstudio.com/src/contrib/nloptr_1.0.4.tar.gz'
Content type 'unknown' 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 grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking nlopt.h usability... no
checking nlopt.h presence... no
checking for nlopt.h... no
configure: Need to download and build NLopt
trying URL 'http://ab-initio.mit.edu/nlopt/nlopt-2.4.2.tar.gz'
Content type 'application/x-gzip' length 2361992 bytes (2.3 MB)
==================================================
downloaded 2.3 MB

configure: Starting to install library to /tmp/Rtmp7A1ldT/R.INSTALL66fffc391ed/nloptr/nlopt-2.4.2
configure: Done installing library to /tmp/Rtmp7A1ldT/R.INSTALL66fffc391ed/nloptr/nlopt-2.4.2
configure: creating ./config.status
config.status: creating src/Makevars
** libs
g++ -I/usr/share/R/include -DNDEBUG      -fpic  -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -g  -c dummy.cpp -o dummy.o
gcc -std=gnu99 -I/usr/share/R/include -DNDEBUG     -I/tmp/Rtmp7A1ldT/R.INSTALL66fffc391ed/nloptr/nlopt-2.4.2/include -fpic  -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -g  -c nloptr.c -o nloptr.o
nloptr.c:42:19: fatal error: nlopt.h: No such file or directory
 #include "nlopt.h"
                   ^
compilation terminated.
make: *** [nloptr.o] Error 1
ERROR: compilation failed for package ‘nloptr’
* removing ‘/home/rd14/R/x86_64-pc-linux-gnu-library/3.3/nloptr’
Warning in install.packages :
  installation of package ‘nloptr’ had non-zero exit status

The downloaded source packages are in
    ‘/tmp/Rtmp4Y3TXJ/downloaded_packages’

非常感谢您的帮助!

谢谢。


你的系统是什么? - Dirk Eddelbuettel
Ubuntu 14.04.4 LTS - user1442363
1
嗯,当Jelmer和我构建这个设置时,它只是工作的。但对你来说最简单的解决方法可能就是安装系统nlopt库,nloptr包将检测并使用它。因此,请执行sudo apt-get install libnlopt-dev,然后再尝试安装nlopt - Dirk Eddelbuettel
1
顺便提一下,对于 lme4 也是同样的操作 —— 只需执行 sudo apt-get install r-cran-lme4。 如果您针对 Ubuntu 指向 CRAN 存储库(或者可能是 Michael 的额外 PPA),您也应该获得当前版本。 以防从源代码构建过于麻烦... - Dirk Eddelbuettel
@DirkEddelbuettel 非常感谢,它完美地工作了。 - user1442363
显示剩余3条评论
2个回答

17

我和Jelmer建立这个设置时,它只在我的Ubuntu机器上正常工作,并且现在仍然如此-无论是通过下载和构建nlopt还是通过系统库。

由于你使用的是Ubuntu操作系统,最简单的解决方法可能是直接安装系统nlopt库,nloptr程序包会检测并使用它。因此,请执行以下操作:

sudo apt-get install libnlopt-dev 

然后再次尝试安装nlopt。

同样地,根据CRAN中Ubuntu的README所述,您应该能够从Michael Rutter的适当PPA中获取lme4,名称为r-cran-lme4


我试图在R 3.4.0中安装carets包,但由于nloptr出现错误而无法完成安装。尝试了这个解决方案后,它成功了! - Luís Telles

0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接