Thursday, November 18, 2021

[SOLVED] Installing R 3.5.0 with --enable-R-shlib

Issue

I am trying to install R 3.5.0 from source with the flag --enable-R-shlib under Linux Mint. Configuring and installing it without the flag works fine, but RStudio requires the flag to be set. However, when running

./configure --enable-R-shlib
make

I get the error

/usr/bin/ld: CommandLineArgs.o: relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
CommandLineArgs.o: error adding symbols: Bad value
collect2: error: ld returned 1 exit status
Makefile:177: recipe for target 'libR.so' failed
make[3]: *** [libR.so] Error 1
make[3]: Leaving directory '/home/hps/Downloads/R-3.5.0/src/main'
Makefile:135: recipe for target 'R' failed
make[2]: *** [R] Error 2
make[2]: Leaving directory '/home/hps/Downloads/R-3.5.0/src/main'
Makefile:28: recipe for target 'R' failed
make[1]: *** [R] Error 1
make[1]: Leaving directory '/home/hps/Downloads/R-3.5.0/src'
Makefile:60: recipe for target 'R' failed
make: *** [R] Error 1

I tried setting the -fPIC flag as mentioned in the error message following the advice from [1]

CC="gcc -fPIC" ./configure --enable-R-shlib

to no avail, I still get the same error message.

[1] Passing a gcc flag through makefile


Solution

Just in case someone else runs into this problem.

The issue is the object files ".o" are already compiled without the -fpic option.

The proper solution is to remove the object files from the first build and recomplile:

make clean
./configure --enable-R-shlib
make -j 4

sudo make install

The -j 4 tells make to spawn four compile processes at a time. Adjust the number to match the number of processor cores.



Answered By - Strom