I am trying to install nloptr
from source in R version 4.1.3 on a cluster (CentOS). However I receive the following error:
/cvmfs/argon.hpc.uiowa.edu/2022.1/prefix/usr/lib/gcc/x86_64-pc-linux-gnu/9.4.0/../../../../x86_64-pc-linux-gnu/bin/ld: cannot find -lnlopt
collect2: error: ld returned 1 exit status
make: *** [/cvmfs/argon.hpc.uiowa.edu/2022.1/apps/linux-centos7-broadwell/gcc-9.4.0/r-4.1.3-ljofaul/rlib/R/share/make/shlib.mk:10: nloptr.so] Error 1
ERROR: compilation failed for package ‘nloptr’
I am on a university cluster and cannot run sudo
commands. After encouragement from @eddelbuettel to contact my sys admin, he figured out the issue. Here's what he wrote:
The build environment for nloptr
uses pkg-config
to get information about nlopt
. It turns out that the pkg-config
file has an error. It has
libdir=${exec_prefix}/lib
but the library is actually located in
libdir=${exec_prefix}/lib64
That does not show up in the packaging environment because LIBRARY_PATH
is set for the dependency chain. I will need to fix the pkg-config
file in the package recipe, but you can work around it as follows:
- load environment modules:
module load stack/2022.1
module load nlopt
- set
LIBRARY_PATH
so linker can find library while launching R session (single line below):
LIBRARY_PATH=$ROOT_NLOPT/lib64:$LIBRARY_PATH R
- install
nloptr
in the R console (single line below):
install.packages(verbose=1,'nloptr')
I originally posted this issue in the nloptr
repo: https://github.com/astamm/nloptr/issues/123. However, @eddelbuettel encouraged me to post an issue here because we suspect that the issue may be the pkg-config
file created by nlopt
.
Here's the output of some of my commands in CentOS:
[itpetersen@argon-login-1 ~]$ module load stack/2022.1
The following have been reloaded with a version change:
1) stack/2020.1 => stack/2022.1
[itpetersen@argon-login-1 ~]$ module load r/4.1.3_gcc-9.4.0
[itpetersen@argon-login-1 ~]$ module load nlopt
[itpetersen@argon-login-1 ~]$ R CMD config --all | grep lib64
LIBnn = lib64
[itpetersen@argon-login-1 ~]$ pkg-config --libs nlopt
-L/cvmfs/argon.hpc.uiowa.edu/2022.1/apps/linux-centos7-broadwell/gcc-9.4.0/nlopt-2.7.0-u5x4377/lib -lnlopt
We think we would want that to be (https://github.com/astamm/nloptr/issues/123#issuecomment-1317199965_):
-L/cvmfs/argon.hpc.uiowa.edu/2022.1/apps/linux-centos7-broadwell/gcc-9.4.0/nlopt-2.7.0-u5x4377/lib64 -lnlopt
That is, /lib64
in my case instead of /lib
. @eddelbuettel, please clarify if I missed anything or got anything wrong!