Giovanni  Spirito
Giovanni Spirito

Reputation: 61

Cannot install nloptr (R 4.0.3, Ubuntu 20.04)

I tried to install nloptr on R 4.0.3, however I get this error:

/usr/bin/ld: /usr/local/lib/libnlopt.a(general.o): relocation R_X86_64_TPOFF32 against `nlopt_srand_called' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: /usr/local/lib/libnlopt.a(mt19937ar.o): relocation R_X86_64_TPOFF32 against `mti' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: /usr/local/lib/libnlopt.a(timer.o): relocation R_X86_64_TPOFF32 against `start_inited.4301' can not be used when making a shared object; recompile with -fPIC
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’
* removing ‘/home/giovanni/R/x86_64-pc-linux-gnu-library/4.0/nloptr’
Warning in install.packages :
  installation of package ‘nloptr’ had non-zero exit status

Can someone point me to a solution?

Thanks in advance.

Upvotes: 2

Views: 3966

Answers (3)

Bingke Jiao
Bingke Jiao

Reputation: 1

I also failed to install the nloptr but had another error.

g++: error: nlopt/lib/libnlopt.a: No such file or directory

I followed others suggestion to install the nlopt first as described in nlopt website. The installation process was

mkdir build
cd build
cmake ..
make
sudo make install

But I found the cmake version which nlopt needed should be higher than 3. The default cmake in my computer was version 2.8.12.2 which was /usr/bin/cmake. So I installed cmake version 3.24.2 in my home directory and compiled the nlopt using absolute path of cmake as ~/software/install/cmake-3.24.2-linux-x86_64/bin/cmake ... And I used sudo to install the nlopt in the computer. I could see the libnlopt.so libnlopt.so.0 libnlopt.so.0.11.1 files in /usr/local/lib64

When I went back to install the nloptr in R. It still failed. I found the cmake failure in the output information of installation. So I add the cmake(version 3.24.2) to my PATH in .bashrc file and then I installed the nloptr successfully.

Upvotes: 0

Naser Nikzad
Naser Nikzad

Reputation: 941

I had a slightly related issue with this package, apt install cmake which was suggested by cli itself fixed the issue.

enter image description here

Upvotes: 1

Vadim Verenich
Vadim Verenich

Reputation: 46

The latest (2.6.2) package of libnlopt-dev is broken in Ubuntu 20, for some reason it is compiled into a static library (.so shared object is missing) I faced the similar problem a couple of days ago. The quick fix is to download NLOPT fron Github and compile it yourself https://nlopt.readthedocs.io/en/latest/NLopt_Installation/ At least, it worked for me.

Upvotes: 3

Related Questions