简体   繁体   English

如何在 Linux 上安装 nloptr

[英]how to install nloptr on Linux

I have a box with antiX, which is a Debian clone.我有一个带有 antiX 的盒子,它是一个 Debian 克隆。 I compiled and installed nlopt and still:我编译并安装了 nlopt 并且仍然:

> install.packages("nloptr")
Installing package into ‘/home/stephen/R/x86_64-pc-linux-gnu-library/3.5’
(as ‘lib’ is unspecified)
trying URL 'https://utstat.toronto.edu/cran/src/contrib/nloptr_1.2.2.2.tar.gz'
Content type 'application/x-gzip' length 2450931 bytes (2.3 MB)
==================================================
downloaded 2.3 MB

* installing *source* package ‘nloptr’ ...
** package ‘nloptr’ successfully unpacked and MD5 sums checked
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... /usr/bin/grep
checking for egrep... /usr/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... yes
checking nlopt.h presence... yes
checking for nlopt.h... yes
configure: Now testing for NLopt version 2.4.0 or greater.
configure: Suitable NLopt library found.
configure: creating ./config.status
config.status: creating src/Makevars
config.status: creating R/PkgFlags.R
** libs
g++  -I"/usr/share/R/include" -DNDEBUG      -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-3.5.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c dummy.cpp -o dummy.o
gcc -std=gnu99 -I"/usr/share/R/include" -DNDEBUG     -I/usr/local/include  -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-3.5.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c init_nloptr.c -o init_nloptr.o
gcc -std=gnu99 -I"/usr/share/R/include" -DNDEBUG     -I/usr/local/include  -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-3.5.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c nloptr.c -o nloptr.o
g++ -shared -L/usr/lib/R/lib -Wl,-z,relro -o nloptr.so dummy.o init_nloptr.o nloptr.o -L/usr/local/lib -lnlopt -L/usr/lib/R/lib -lR
installing to /home/stephen/R/x86_64-pc-linux-gnu-library/3.5/nloptr/libs
** R
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded
Error: package or namespace load failed for ‘nloptr’ in dyn.load(file, DLLpath = DLLpath, ...):
 unable to load shared object '/home/stephen/R/x86_64-pc-linux-gnu-library/3.5/nloptr/libs/nloptr.so':
  libnlopt.so.0: cannot open shared object file: No such file or directory
Error: loading failed
Execution halted
ERROR: loading failed
* removing ‘/home/stephen/R/x86_64-pc-linux-gnu-library/3.5/nloptr’

The downloaded source packages are in
    ‘/tmp/RtmpEtHKlT/downloaded_packages’
Warning message:
In install.packages("nloptr") :
  installation of package ‘nloptr’ had non-zero exit status

I went into the nloptr folder and ran ./configure and the compile statements that I see in the output and I have nloptr.so in the src folder.我进入 nloptr 文件夹并运行 ./configure 和我在输出中看到的编译语句,并且我在 src 文件夹中有 nloptr.so 。 Is there a way to continue the install manually and copy what needs to be copied?有没有办法手动继续安装并复制需要复制的内容? or can I check that .so if it works?或者我可以检查一下.so是否有效?

$ ldd nloptr.so
    linux-vdso.so.1 (0x00007ffdb6dc1000)
    libnlopt.so.0 => not found
    libR.so => /lib/libR.so (0x00007f0e9e6b4000)
    libstdc++.so.6 => /lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f0e9e530000)
    libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f0e9e3ad000)
    libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f0e9e393000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f0e9e1d2000)
    libblas.so.3 => /lib/x86_64-linux-gnu/libblas.so.3 (0x00007f0e9e163000)
    libgfortran.so.5 => /lib/x86_64-linux-gnu/libgfortran.so.5 (0x00007f0e9def5000)
    libquadmath.so.0 => /lib/x86_64-linux-gnu/libquadmath.so.0 (0x00007f0e9deb3000)
    libreadline.so.7 => /lib/x86_64-linux-gnu/libreadline.so.7 (0x00007f0e9dc66000)
    libpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007f0e9dbf2000)
    liblzma.so.5 => /lib/x86_64-linux-gnu/liblzma.so.5 (0x00007f0e9dbca000)
    libbz2.so.1.0 => /lib/x86_64-linux-gnu/libbz2.so.1.0 (0x00007f0e9dbb5000)
    libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f0e9d997000)
    librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f0e9d98d000)
    libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f0e9d988000)
    libicuuc.so.63 => /lib/x86_64-linux-gnu/libicuuc.so.63 (0x00007f0e9d7b9000)
    libicui18n.so.63 => /lib/x86_64-linux-gnu/libicui18n.so.63 (0x00007f0e9d4de000)
    libgomp.so.1 => /lib/x86_64-linux-gnu/libgomp.so.1 (0x00007f0e9d4ab000)
    libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f0e9d48a000)
    /lib64/ld-linux-x86-64.so.2 (0x00007f0e9eb5b000)
    libtinfo.so.6 => /lib/x86_64-linux-gnu/libtinfo.so.6 (0x00007f0e9d45c000)
    libicudata.so.63 => /lib/x86_64-linux-gnu/libicudata.so.63 (0x00007f0e9ba6c000)

$ ls /usr/local/lib/libnl*
/usr/local/lib/libnlopt.so  /usr/local/lib/libnlopt.so.0  /usr/local/lib/libnlopt.so.0.10.0

Cheers干杯

Stephen斯蒂芬

As discussed in comments above the issue here was a 'unconventional' (and hence not-working) 'installation' of the nlopt library: one cannot just untar it somewhere as the dynamic linker needs to know about it, update its cache etc.正如上面评论中所讨论的,这里的问题是 nlopt 库的“非常规”(因此不工作)“安装”:不能只是在某个地方解压它,因为动态链接器需要了解它、更新它的缓存等。

So in short the recommended answer is to, where available as a suitable version, install the -dev package from the distro.所以简而言之,推荐的答案是,如果有合适的版本,从发行版安装-dev包。 Here the command is这里的命令是

sudo apt install libnlopt-dev

after which configure in the R package sees, and also gets to use it as the corresponding shared library itself gets installed from the libnlopt0 package.之后,R 包中的configure会看到,并且还可以使用它,因为相应的共享库本身是从libnlopt0包安装的。 (And we answered a few times why the -dev package is always needed for building as opposed to merely running via the shared library package). (我们多次回答了为什么总是需要-dev包来构建而不是仅仅通过共享库包运行)。

The previous solution did not worked on my machine (Ubuntu 18.04, R 4.2.0).以前的解决方案在我的机器上不起作用(Ubuntu 18.04,R 4.2.0)。 In installed nlopt library from github using在从github安装nlopt库中使用

git clone https://github.com/stevengj/nlopt.git
cd nlopt
mkdir build
cd build
cmake ..
make
sudo make install

Then install.packages("nloptr") worked with no issues然后install.packages("nloptr")没有问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM