This question is similar to this previous question with respect to RcppArmadillo.
Some quick context:
I currently must work on a CentOS 5 system. Naturally, the compiler that comes with CentOS 5 was too old so we installed gcc-4.8.3. Now, others were concerned about back compatibility with the old compiler so the new gcc was placed in the opt
directory. In order to use the upgraded g++ I must set the LD_LIBRARY_PATH
in R with Sys.setenv
Sys.setenv(LD_LIBRARY_PATH = "/opt/gcc-4.8.3/rtf/lib:/opt/gcc-4.8.3/rtf/lib64")
Now, I also need to install an archived version of RcppArmadillo. I get the archived package from CRAN and install with:
install.packages("RcppArmadillo_0.3.930.1.tar.gz", repose=NULL, type="source")
This appears to work without issue but when I try to load the library I get the following error:
Error in dyn.load(file, DLLpath = DLLpath, ...) :
unable to load shared object '/usr/lib64/R/library/RcppArmadillo/libs/RcppArmadillo.so':
/usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.9' not found (required by /usr/lib64/R/library/RcppArmadillo/libs/RcppArmadillo.so)
From what think I understand is that the libstdc++.so
file that is found is too old, i.e. not the newer one that is in the opt
directory. I thought this would have been solved by setting LD_LIBRARY_PATH
above but it seems to still be looking in /usr/lib64/
. Is there any way for me to have R look in this other directory to get the appropriate so
file? Naturally if I have done something strange that would have caused this I am open to other solutions (besides overwriting the old gcc version).
EDIT
I have also noticed that upon installation the -shared
is again showing the usr/
path as opposed to the opt/
path. This is what I want to update so R will also search the opt
directory.
* installing *source* package âRcppArmadilloâ ...
** package âRcppArmadilloâ successfully unpacked and MD5 sums checked
* checking LAPACK_LIBS divide-and-conquer complex SVD unavailable via R-supplied LAPACK
* divide-and-conquer algorithm for complex SVD will be redirected to default
** libs
g++ -I/usr/include/R -DNDEBUG -I/usr/local/include -I"/usr/lib64/R/library/Rcpp/include" -I../inst/include -fpic -g -O3 -Wall -pipe -pedantic -Wno-variadic-macros -c RcppArmadillo.cpp -o RcppArmadillo.o
g++ -I/usr/include/R -DNDEBUG -I/usr/local/include -I"/usr/lib64/R/library/Rcpp/include" -I../inst/include -fpic -g -O3 -Wall -pipe -pedantic -Wno-variadic-macros -c RcppExports.cpp -o RcppExports.o
g++ -I/usr/include/R -DNDEBUG -I/usr/local/include -I"/usr/lib64/R/library/Rcpp/include" -I../inst/include -fpic -g -O3 -Wall -pipe -pedantic -Wno-variadic-macros -c fastLm.cpp -o fastLm.o
g++ -shared -L/usr/local/lib64 -o RcppArmadillo.so RcppArmadillo.o RcppExports.o fastLm.o -L/usr/lib64/R/lib -lRlapack -L/usr/lib64/R/lib -lRblas -L/usr/bin/gfortran -L/usr/lib64/R/lib -lR
UPDATE
I have also tried manually appending the opt
directory by creating a Makevars
file in the .R
directory by setting PKG_LIBS += -L$(OPT_PATH)
, where OPT_PATH = /opt/gcc-4.8.3/rtf/lib64
. The shared
line during compilation looks like this:
g++ -shared -L/usr/local/lib64 -o RcppArmadillo.so RcppArmadillo.o RcppExports.o fastLm.o -L/usr/lib64/R/lib -lRlapack -L/usr/lib64/R/lib -lRblas -L/usr/bin/gfortran -L/opt/gcc-4.8.3/rtf/lib64 -L/usr/lib64/R/lib -lR
But I still get the same error:
/usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.9' not found
Even stranger (at least to me) is that running ldd
shows that the RcppArmadillo.so
file is pointing to the correct file.
ldd /usr/lib64/R/library/RcppArmadillo/libs/RcppArmadillo.so
...
libstdc++.so.6 => /opt/gcc-4.8.3/rtf/lib64/libstdc++.so.6 (0x00002ae950a3d000)
...
which does contain GLIBCXX_3.4.9
I eventually came to a solution with the current system. I needed to coordinate with our IT department to get temporary sudo privileges. Then, after switching to root I needed to export the following two environmental variables.
export LD_LIBRARY_PATH=/opt/gcc-4.8.3/rtf/lib:/opt/gcc-4.8.3/rtf/lib64
export LD_RUN_PATH=/opt/gcc-4.8.3/rtf/lib:/opt/gcc-4.8.3/rtf/lib64
Then, while still as root, I opened R and ran
install.packages('RcppArmadillo')
This installed the latest RcppArmadillo package on our CentOS 5.8 system with our gcc-4.8.3 compiler in its non-standard location in opt
. I verified the installation worked by switching to a normal user and loading the package successfully.