Search code examples
rubuntunlopt

Problem installing "nloptr" in R 4.2.2 on Ubuntu 22.04


My installation of "ggpubr" on Rstudio (based on R 4.2.2) in Ubuntu 22.04 failed because of issues in installing "nloptr". I installed NLOPT based on guides in https://nlopt.readthedocs.io/en/latest/NLopt_Installation/, but nloptr installation is still failing but with another kind of error.

Here are the last lines:

g++ -std=gnu++11 -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions -flto=auto -ffat-lto-objects -flto=auto -Wl,-z,relro -o nloptr.so init_nloptr.o nloptr.o test-C-API.o test-runner.o -llapack -lblas -lgfortran -lm -lquadmath -L/usr/local/lib -lnlopt -L/usr/lib/R/lib -lR
/usr/bin/ld: cannot find -llapack: No such file or directory
/usr/bin/ld: cannot find -lblas: No such file or directory
/usr/bin/ld: cannot find -lgfortran: No such file or directory
collect2: error: ld returned 1 exit status
make: *** [/usr/share/R/share/make/shlib.mk:10: nloptr.so] Error 1
ERROR: compilation failed for package ‘nloptr’

Any help is appreciated.

Best, Amir


Solution

  • The comments by @jay.sf and myself give you the narrowest answer: you attempt to build from source, and compiling and linking requires the so-called -dev packages. So install r-base-dev.

    Looking beyond this for a second though, you are on Ubuntu 22.04 and you have r-cran-nloptr inside the distribution too (albeit an older version). So sudo apt install r-cran-nloptr works as well.

    And since this summer there is r2u which gives you (on Ubuntu 20.04 and Ubuntu 22.04) every CRAN package as an Ubuntu binary and is generally current. It is easy to set up and the command install.packages("ggpubr") would then reliably and quickly install the package and all its dependencies from binaries.