• Create Time: 2022-02-11
  • Update Time: 2022-02-18

Processes

mkdir -p $HOME/pkgconfig $HOME/softwares $HOME/tmp 


cd $HOME/tmp
wget https://github.com/stevengj/nlopt/archive/refs/tags/v2.7.1.tar.gz

tar -zxvf v2.7.1.tar.gz
cd nlopt-2.7.1
mkdir build
cd build

cmake -DCMAKE_INSTALL_PREFIX=$HOME/softwares/nlopt ..
make 
make install

cp $HOME/softwares/nlopt/lib/pkgconfig/nlopt.pc $HOME/pkgconfig

export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:$HOME/pkgconfig


# Then you could install the package: nloptr in the R environment

In the R environment

install.packages('nloptr')

Issues

I am not sure if everyone will get this kind of issue

Error: package or namespace load failed for ‘nloptr’ in dyn.load(file, DLLpath = DLLpath, ...):
 unable to load shared object '$HOME/R/x86_64-pc-linux-gnu-library/4.1/00LOCK-nloptr/00new/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/R/x86_64-pc-linux-gnu-library/4.1/nloptr’

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

Even though, the pkg-config has confirmed we have had installed nlopt package.

checking if pkg-config knows NLopt... yes
checking for pkg-config checking NLopt version... >= 2.7.0
configure: creating ./config.status
config.status: creating src/Makevars

Fix

Then I create a soft-links of the libnlop in the $HOME/lib directory.

cd $HOME/lib
ln -s $HOME/softwares/nlopt/lib/lib* ./
export LD_LIBRARY_PATH=$HOME/lib/:${LD_LIBRARY_PATH}

Finally, we could install the R package in the R.

install.packages('nloptr')

TL;DR

The package installation is similar as the previous hdf5r installation. There’re some differences in the install processes:

  1. The installation was based on cmake rather than make only.

  2. As the nloptr (with r in the name) package installation was based on the pkg-config to find the dependency libraries, we can’t put the libraries (xxx.so files) in the $HOME/lib directory and then the nloptr knows where they are. We need to to tell pkg-config where I put the libraries.