nlopt icon indicating copy to clipboard operation
nlopt copied to clipboard

Error installing `nloptr` from source on CentOS cluster

Open isaactpetersen opened this issue 2 years ago • 4 comments

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:

  1. load environment modules:
module load stack/2022.1
module load nlopt
  1. set LIBRARY_PATH so linker can find library while launching R session (single line below):
LIBRARY_PATH=$ROOT_NLOPT/lib64:$LIBRARY_PATH R
  1. 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!

isaactpetersen avatar Nov 16 '22 17:11 isaactpetersen

To add to this please try to locate the nlopt.pc file on your system (likely "next to" where the library is) and show its content. My thinking is that has the lib/ entry you need to be lib64.

(For context: nloptr is the R wrapper for nlopt. It asks pkg-config at install time if an nlopt installation is present, and we found here that the linking instructions were insufficient due to the lib != lib64 issue.)

eddelbuettel avatar Nov 16 '22 17:11 eddelbuettel

FYI, I get a blank response when I type locate nlopt.pc

isaactpetersen avatar Nov 16 '22 17:11 isaactpetersen

Sorry your misunderstand what locate does. It works when fed directories (standard system). I didn't mean to imply you could just call it on your cluster. My words should have been "look for it" (implying "mechanically") and my hint was ("likely 'next to' [..] the library). Or maybe where pkg-config has them. pkg-config --libs nlopt reads from it. If you can show us the whole file.

eddelbuettel avatar Nov 16 '22 17:11 eddelbuettel

Turns out we don't have locate installed, but here is the location of the file based on the find command:

$ find $ROOT_NLOPT -name nlopt.pc
/usr/share/apps/2022.1/arch/gcc-9.4.0/nlopt-2.7.0/lib64/pkgconfig/nlopt.pc

$ cat $ROOT_NLOPT/lib64/pkgconfig/nlopt.pc
prefix=/cvmfs/argon.hpc.uiowa.edu/2022.1/apps/linux-centos7-broadwell/gcc-9.4.0/nlopt-2.7.0-u5x4377
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir=${prefix}/include

Name: NLopt
Description: nonlinear optimization libary
Version: 2.7.0
Libs: -L${libdir} -lnlopt
Libs.private: -lm
Cflags: -I${includedir}

isaactpetersen avatar Nov 16 '22 21:11 isaactpetersen

I'm still seeing the same issue with 2.7.1 after installing lib64/pkgconfig/nlopt.pc has libdir=${exec_prefix}/lib but needs libdir=${exec_prefix}/lib64

mrgum avatar Aug 21 '24 14:08 mrgum

What is your compiler? It is likely too old so maybe look into devtoolset for centos (there are different versions) or maybe try an OS that is not end-of-lifed and has current tools. nloptr is happy at CRAN with recent versions of OS and toolchain:

image

eddelbuettel avatar Aug 21 '24 14:08 eddelbuettel

OS is Amazon Linux 2 eol is 2025-06-30 I've installed cmake 3.29.6 gcc version is gcc (GCC) 7.3.1 20180712 (Red Hat 7.3.1-17)

mrgum avatar Aug 21 '24 15:08 mrgum

should be ok with 2.8.0

jschueller avatar Aug 21 '24 16:08 jschueller

cmake is not the guilty party here though the build uses it. gcc/g++ version 7 is your problem. devtoolset maybe be your solution.

The other, of course, is to rely on a libnlopt from your distro, if it exists, and nloptr will use it and not fall back to source.

eddelbuettel avatar Aug 21 '24 16:08 eddelbuettel

it is thank you! docs need an update?

https://nlopt.readthedocs.io/en/latest/#download-and-installation

Download and installation

Version 2.7.1 of NLopt is the latest version available from GitHub:

mrgum avatar Aug 21 '24 17:08 mrgum