how to install nloptr on Linux

Solution for how to install nloptr on Linux
is Given Below:

I have a box with antiX, which is a Debian clone. I compiled and installed nlopt and still:

> install.packages("nloptr")
Installing package into ‘/home/stephen/R/x86_64-pc-linux-gnu-library/3.5’
(as ‘lib’ is unspecified)
trying URL ''
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 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/': 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
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 in the src folder. 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?

$ ldd (0x00007ffdb6dc1000) => not found => /lib/ (0x00007f0e9e6b4000) => /lib/x86_64-linux-gnu/ (0x00007f0e9e530000) => /lib/x86_64-linux-gnu/ (0x00007f0e9e3ad000) => /lib/x86_64-linux-gnu/ (0x00007f0e9e393000) => /lib/x86_64-linux-gnu/ (0x00007f0e9e1d2000) => /lib/x86_64-linux-gnu/ (0x00007f0e9e163000) => /lib/x86_64-linux-gnu/ (0x00007f0e9def5000) => /lib/x86_64-linux-gnu/ (0x00007f0e9deb3000) => /lib/x86_64-linux-gnu/ (0x00007f0e9dc66000) => /lib/x86_64-linux-gnu/ (0x00007f0e9dbf2000) => /lib/x86_64-linux-gnu/ (0x00007f0e9dbca000) => /lib/x86_64-linux-gnu/ (0x00007f0e9dbb5000) => /lib/x86_64-linux-gnu/ (0x00007f0e9d997000) => /lib/x86_64-linux-gnu/ (0x00007f0e9d98d000) => /lib/x86_64-linux-gnu/ (0x00007f0e9d988000) => /lib/x86_64-linux-gnu/ (0x00007f0e9d7b9000) => /lib/x86_64-linux-gnu/ (0x00007f0e9d4de000) => /lib/x86_64-linux-gnu/ (0x00007f0e9d4ab000) => /lib/x86_64-linux-gnu/ (0x00007f0e9d48a000)
    /lib64/ (0x00007f0e9eb5b000) => /lib/x86_64-linux-gnu/ (0x00007f0e9d45c000) => /lib/x86_64-linux-gnu/ (0x00007f0e9ba6c000)

$ ls /usr/local/lib/libnl*
/usr/local/lib/  /usr/local/lib/  /usr/local/lib/



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.

So in short the recommended answer is to, where available as a suitable version, install the -dev package from the distro. 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. (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).