我正在通过R控制台安装nloptr
软件包。
有一个流行的问题,建议使用sudo apt-get install libnlopt-dev
通过apt安装nloptr。我确实尝试过,但没有成功。如果您看到详细信息,则会发现该设置实际上检测到了nloptr库configure: Suitable NLopt library found
。
但是,似乎有这个奇怪的错误,不允许我安装该库。我什至尝试从tar.gz软件包中安装旧版本,但仍然存在相同的错误。
> install.packages('nloptr')
Installing package into ‘/usr/local/lib/R/site-library’
(as ‘lib’ is unspecified)
trying URL 'https://cloud.r-project.org/src/contrib/nloptr_1.2.1.tar.gz'
Content type 'application/x-gzip' length 2448313 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... /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... yes
checking nlopt.h presence... yes
checking for nlopt.h... yes
configure: Now testing for NLopt versison number.
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-AitvI6/r-base-3.4.4=. -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-AitvI6/r-base-3.4.4=. -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-AitvI6/r-base-3.4.4=. -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,-Bsymbolic-functions -Wl,-z,relro -o nloptr.so dummy.o init_nloptr.o nloptr.o -L/usr/local/lib -lnlopt -lm -L/usr/lib/R/lib -lR
/usr/bin/x86_64-linux-gnu-ld: /usr/local/lib/libnlopt.a(general.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
/usr/bin/x86_64-linux-gnu-ld: /usr/local/lib/libnlopt.a(optimize.o): relocation R_X86_64_32S against `.text' can not be used when making a shared object; recompile with -fPIC
/usr/bin/x86_64-linux-gnu-ld: /usr/local/lib/libnlopt.a(mt19937ar.o): relocation R_X86_64_TPOFF32 against `mti' can not be used when making a shared object; recompile with -fPIC
/usr/bin/x86_64-linux-gnu-ld: /usr/local/lib/libnlopt.a(timer.o): relocation R_X86_64_TPOFF32 against `start_inited.4227' can not be used when making a shared object; recompile with -fPIC
/usr/bin/x86_64-linux-gnu-ld: /usr/local/lib/libnlopt.a(cdirect.o): relocation R_X86_64_32 against `.text' can not be used when making a shared object; recompile with -fPIC
/usr/bin/x86_64-linux-gnu-ld: /usr/local/lib/libnlopt.a(pnet.o): relocation R_X86_64_32 against `.bss' can not be used when making a shared object; recompile with -fPIC
/usr/bin/x86_64-linux-gnu-ld: /usr/local/lib/libnlopt.a(crs.o): relocation R_X86_64_32 against `.text' can not be used when making a shared object; recompile with -fPIC
/usr/bin/x86_64-linux-gnu-ld: /usr/local/lib/libnlopt.a(mlsl.o): relocation R_X86_64_32 against `.text' can not be used when making a shared object; recompile with -fPIC
/usr/bin/x86_64-linux-gnu-ld: /usr/local/lib/libnlopt.a(ccsa_quadratic.o): relocation R_X86_64_32 against `.text' can not be used when making a shared object; recompile with -fPIC
/usr/bin/x86_64-linux-gnu-ld: /usr/local/lib/libnlopt.a(mma.o): relocation R_X86_64_32 against `.text' can not be used when making a shared object; recompile with -fPIC
/usr/bin/x86_64-linux-gnu-ld: /usr/local/lib/libnlopt.a(cobyla.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
/usr/bin/x86_64-linux-gnu-ld: /usr/local/lib/libnlopt.a(newuoa.o): relocation R_X86_64_32 against `.text' can not be used when making a shared object; recompile with -fPIC
/usr/bin/x86_64-linux-gnu-ld: /usr/local/lib/libnlopt.a(nldrmd.o): relocation R_X86_64_32 against `.text' can not be used when making a shared object; recompile with -fPIC
/usr/bin/x86_64-linux-gnu-ld: /usr/local/lib/libnlopt.a(sbplx.o): relocation R_X86_64_32 against `.text' can not be used when making a shared object; recompile with -fPIC
/usr/bin/x86_64-linux-gnu-ld: /usr/local/lib/libnlopt.a(auglag.o): relocation R_X86_64_32 against `.text' can not be used when making a shared object; recompile with -fPIC
/usr/bin/x86_64-linux-gnu-ld: /usr/local/lib/libnlopt.a(isres.o): relocation R_X86_64_32 against `.text' can not be used when making a shared object; recompile with -fPIC
/usr/bin/x86_64-linux-gnu-ld: /usr/local/lib/libnlopt.a(slsqp.o): relocation R_X86_64_32S against `.rodata' can not be used when making a shared object; recompile with -fPIC
/usr/bin/x86_64-linux-gnu-ld: /usr/local/lib/libnlopt.a(esch.o): relocation R_X86_64_32 against `.text' can not be used when making a shared object; recompile with -fPIC
/usr/bin/x86_64-linux-gnu-ld: /usr/local/lib/libnlopt.a(redblack.o): relocation R_X86_64_32S against symbol `nil' can not be used when making a shared object; recompile with -fPIC
/usr/bin/x86_64-linux-gnu-ld: /usr/local/lib/libnlopt.a(sobolseq.o): relocation R_X86_64_32S against `.rodata' can not be used when making a shared object; recompile with -fPIC
/usr/bin/x86_64-linux-gnu-ld: /usr/local/lib/libnlopt.a(DIRect.o): relocation R_X86_64_32 against `.rodata.str1.8' can not be used when making a shared object; recompile with -fPIC
/usr/bin/x86_64-linux-gnu-ld: /usr/local/lib/libnlopt.a(DIRsubrout.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
/usr/bin/x86_64-linux-gnu-ld: final link failed: Nonrepresentable section on output
collect2: error: ld returned 1 exit status
/usr/share/R/share/make/shlib.mk:6: recipe for target 'nloptr.so' failed
make: *** [nloptr.so] Error 1
ERROR: compilation failed for package ‘nloptr’
* removing ‘/usr/local/lib/R/site-library/nloptr’
The downloaded source packages are in
‘/tmp/RtmpNXGKfk/downloaded_packages’
Warning message:
In install.packages("nloptr") :
installation of package ‘nloptr’ had non-zero exit status
我提到了很多SO问题,但无法弄清楚该怎么做。而且,配置文件很大,我不知道在哪里进行更改
答案 0 :(得分:0)
由于@JBGruber的评论,我找到了另一种解决方法。
sudo apt-get install r-cran-nloptr