Problem installing R package rstan (to install brms) on CentOS7

rstan

#1

Hi!

I was sent here by the AFNI forum since their packages need the R-package “brms” to work and they don’t usually work with CentOS. The installaiton of brms fails since I’m not able to install rstan, so let’s focus on that.

Firstly some info:
OS:
rpm -q centos-release
centos-release-7-6.1810.2.el7.centos.x86_64

Devtools:
     devtools::session_info("rstan")
    ─ Session info ───────────────────────────────────────────────────────────────
     setting  value                       
     version  R version 3.5.1 (2018-07-02)
     os       CentOS Linux 7 (Core)       
     system   x86_64, linux-gnu           
     ui       X11                         
     language (EN)                        
     collate  en_US.UTF-8                 
     ctype    en_US.UTF-8                 
     tz       Europe/Stockholm            
     date     2019-01-11                  

─ Packages ───────────────────────────────────────────────────────────────────
 ! package * version date lib source
 R rstan     <NA>    <NA> [?] <NA>  

[1] /home/robka/R
[2] /usr/lib64/R/library
[3] /usr/share/R/library

 R ── Package was removed from disk.

Makevars:

> writeLines(readLines(file.path(Sys.getenv("HOME"), ".R/Makevars")))
Error in file(con, "r") : cannot open the connection
In addition: Warning message:
In file(con, "r") :
  cannot open file '/home/robka/.R/Makevars': No such file or directory

The full question is accessible form the link in the top but I’ll do a summary here.

I had trouble installing rstan, shinystan and brms on my Ubuntu machine as well but it was simply solved by:

sudo apt-get install r-cran-rstan
sudo apt-get install r-cran-shinystan
sudo apt-get install r-cran-brms 

I can’t seem to find the corresponding yum install solution. So I’m stuck trying to make it work via the install.packages(“rstan”) approach.

So, THE MAIN PROBLEM I HAVE is this classical error:

Error in .shlib_internal(args) : 
  C++14 standard requested but CXX14 is not defined

First I just checked if the C++ tool-chain (from another post here):

> pkgbuild::has_build_tools(debug = TRUE)
Trying to compile a simple C file
Running /usr/lib64/R/bin/R CMD SHLIB foo.c
gcc -m64 -std=gnu99 -I"/usr/include/R" -DNDEBUG   -I/usr/local/include   -fpic  -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches   -m64 -mtune=generic  -c foo.c -o foo.o
gcc -m64 -std=gnu99 -shared -L/usr/lib64/R/lib -Wl,-z,relro -o foo.so foo.o -L/usr/lib64/R/lib -lR
 
[1] TRUE
> 

Which should mean that " your C++ toolchain is properly installed".

Then the internet tells me to configure the ~/R/Makevars file. First of, I don’t have it. I found one here instead:

~/R/RcppEigen/skeleton/Makevars:
    ## With Rcpp 0.11.0 and later, we no longer need to set PKG_LIBS as there is
    ## no user-facing library. The include path to headers is already set by R.
    #PKG_LIBS = 

## With R 3.1.0 or later, you can uncomment the following line to tell R to 
## enable compilation with C++11 (or even C++14) where available
#CXX_STD = CXX11

So I tried to configure it in different ways, also by making a copy to ~/R/Makevars. I tried e.g.:

1. Just uncomment CXX_STD = CXX11 then start R and tried installing
2. Uncomment and change it to CXX_STD = CXX14 then start R and tried installing
3. Keep the comment and added (tried seperatley):
a) CXX14 = g++
CXX14FLAGS = -O3
b) CXX14 = clang++
CXX14FLAGS = -O3
c) CXX14 = g++ -std=c++1y
4. Then I commented everything and copied the file to ~/R/Makevars and tried all the combinations above. 

But I still got the same error and R never seem to have seen these option:

[robka@n etc]$ R CMD config CXX11
g++ -m64
[robka@n etc]$ R CMD config CXX11FLAGS
-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic
[robka@n etc]$ R CMD config CXX14

[robka@n2 etc]$ R CMD config CXX14FLAGS

So then the internet took me to this file:
/usr/lib64/R/etc/Malkeconf

I tried a couple of edits, eg:

    CXX14 = g++
    CXX14FLAGS = -O3
    CXX14PICFLAGS =
    CXX14STD =

And now R sees it:

    [robka@n etc]$ R CMD config CXX14
    g++
    [robka@n2 etc]$ R CMD config CXX14FLAGS
    -O3

Now I no longer the error C++14 standard requested but CXX14 is not defined when trying to install ‘rstan’, it tries to compile but fails. There is a lot of output but this segment is repeated over and over:

In file included from /home/robka/R/StanHeaders/include/src/stan/lang/ast.hpp:65:0,
                 from /home/robka/R/StanHeaders/include/src/stan/lang/ast_def.cpp:7,
                 from lang__ast_def.cpp:18:
/home/robka/R/StanHeaders/include/src/stan/lang/ast/sigs/function_signatures.hpp:306:17: note: template<class T> stan::lang::expr_type stan::lang::function_signatures::rng_return_type(const stan::lang::expr_type&, const stan::lang::expr_type&, const stan::lang::expr_type&)
       expr_type rng_return_type(const expr_type& t,
                 ^
/home/robka/R/StanHeaders/include/src/stan/lang/ast/sigs/function_signatures.hpp:306:17: note:   template argument deduction/substitution failed:
In file included from /home/robka/R/StanHeaders/include/src/stan/lang/ast/sigs/function_signatures_def.hpp:486:0,
                 from /home/robka/R/StanHeaders/include/src/stan/lang/ast_def.cpp:119,
                 from lang__ast_def.cpp:18:
/home/robka/R/StanHeaders/include/src/stan/lang/function_signatures.h:1366:57: note:   cannot convert ‘t’ (type ‘const int’) to type ‘const stan::lang::expr_type&’
     add("weibull_rng", rng_return_type<double_type>(t, u), t, u);

Ending with:

make: *** [lang__ast_def.o] Error 1
ERROR: compilation failed for package ‘rstan’
* removing ‘/home/robka/R/rstan’

The downloaded source packages are in
	‘/tmp/Rtmp291Q9L/downloaded_packages’
Warning message:
In install.packages("rstan") :
  installation of package ‘rstan’ had non-zero exit status

I also tried (from the web) to set CXX14STD = -std=gnu++14 which gives an error about gnu++14 is not a valid option. I found out that on older gcc versions you had to type -std=c++1y instead of gnu++14. Using this it did not complain about the option and ran. But again the compilation fails. It also fails if I change it to CXX14STD = -std=gnu++1y instead of CXX14STD = -std=c++1y. The error messages of these two settings are probably identical. So when adding a CXX14STD option the error message changes from the one paste above to:

> install.packages("rstan")
Installing package into ‘/home/robka/R’
(as ‘lib’ is unspecified)
--- Please select a CRAN mirror for use in this session ---
trying URL '[ftp.acc.umu.se];
Content type 'application/x-gzip' length 838052 bytes (818 KB)
==================================================
downloaded 818 KB

* installing *source* package ‘rstan’ ...
** package ‘rstan’ successfully unpacked and MD5 sums checked
** libs
g++ -std=c++1y -I"/usr/include/R" -DNDEBUG -I"../inst/include" -I"`"/usr/lib64/R/bin/Rscript" --vanilla -e "cat(system.file('include', 'src', package = 'StanHeaders'))"`" -DBOOST_DISABLE_ASSERTS -DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION -I"/home/robka/R/Rcpp/include" -I"/home/robka/R/RcppEigen/include" -I"/home/robka/R/BH/include" -I"/home/robka/R/StanHeaders/include" -I/usr/local/include     -O3 -c chains.cpp -o chains.o
In file included from /home/robka/R/BH/include/boost/random/detail/integer_log2.hpp:19:0,
                 from /home/robka/R/BH/include/boost/random/detail/large_arithmetic.hpp:19,
                 from /home/robka/R/BH/include/boost/random/detail/const_mod.hpp:23,
                 from /home/robka/R/BH/include/boost/random/linear_congruential.hpp:30,
                 from /home/robka/R/BH/include/boost/random/additive_combine.hpp:27,
                 from chains.cpp:29:
/home/robka/R/BH/include/boost/pending/integer_log2.hpp:7:89: note: #pragma message: This header is deprecated. Use <boost/integer/integer_log2.hpp> instead.
 BOOST_HEADER_DEPRECATED("<boost/integer/integer_log2.hpp>");
                                                                                         ^
g++ -std=c++1y -I"/usr/include/R" -DNDEBUG -I"../inst/include" -I"`"/usr/lib64/R/bin/Rscript" --vanilla -e "cat(system.file('include', 'src', package = 'StanHeaders'))"`" -DBOOST_DISABLE_ASSERTS -DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION -I"/home/robka/R/Rcpp/include" -I"/home/robka/R/RcppEigen/include" -I"/home/robka/R/BH/include" -I"/home/robka/R/StanHeaders/include" -I/usr/local/include     -O3 -c init.cpp -o init.o
g++ -std=c++1y -I"/usr/include/R" -DNDEBUG -I"../inst/include" -I"`"/usr/lib64/R/bin/Rscript" --vanilla -e "cat(system.file('include', 'src', package = 'StanHeaders'))"`" -DBOOST_DISABLE_ASSERTS -DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION -I"/home/robka/R/Rcpp/include" -I"/home/robka/R/RcppEigen/include" -I"/home/robka/R/BH/include" -I"/home/robka/R/StanHeaders/include" -I/usr/local/include     -O3 -c lang__ast_def.cpp -o lang__ast_def.o
g++ -std=c++1y -I"/usr/include/R" -DNDEBUG -I"../inst/include" -I"`"/usr/lib64/R/bin/Rscript" --vanilla -e "cat(system.file('include', 'src', package = 'StanHeaders'))"`" -DBOOST_DISABLE_ASSERTS -DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION -I"/home/robka/R/Rcpp/include" -I"/home/robka/R/RcppEigen/include" -I"/home/robka/R/BH/include" -I"/home/robka/R/StanHeaders/include" -I/usr/local/include     -O3 -c lang__grammars__bare_type_grammar_inst.cpp -o lang__grammars__bare_type_grammar_inst.o
g++ -std=c++1y -I"/usr/include/R" -DNDEBUG -I"../inst/include" -I"`"/usr/lib64/R/bin/Rscript" --vanilla -e "cat(system.file('include', 'src', package = 'StanHeaders'))"`" -DBOOST_DISABLE_ASSERTS -DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION -I"/home/robka/R/Rcpp/include" -I"/home/robka/R/RcppEigen/include" -I"/home/robka/R/BH/include" -I"/home/robka/R/StanHeaders/include" -I/usr/local/include     -O3 -c lang__grammars__expression07_grammar_inst.cpp -o lang__grammars__expression07_grammar_inst.o
g++ -std=c++1y -I"/usr/include/R" -DNDEBUG -I"../inst/include" -I"`"/usr/lib64/R/bin/Rscript" --vanilla -e "cat(system.file('include', 'src', package = 'StanHeaders'))"`" -DBOOST_DISABLE_ASSERTS -DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION -I"/home/robka/R/Rcpp/include" -I"/home/robka/R/RcppEigen/include" -I"/home/robka/R/BH/include" -I"/home/robka/R/StanHeaders/include" -I/usr/local/include     -O3 -c lang__grammars__expression_grammar_inst.cpp -o lang__grammars__expression_grammar_inst.o
g++ -std=c++1y -I"/usr/include/R" -DNDEBUG -I"../inst/include" -I"`"/usr/lib64/R/bin/Rscript" --vanilla -e "cat(system.file('include', 'src', package = 'StanHeaders'))"`" -DBOOST_DISABLE_ASSERTS -DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION -I"/home/robka/R/Rcpp/include" -I"/home/robka/R/RcppEigen/include" -I"/home/robka/R/BH/include" -I"/home/robka/R/StanHeaders/include" -I/usr/local/include     -O3 -c lang__grammars__functions_grammar_inst.cpp -o lang__grammars__functions_grammar_inst.o
g++ -std=c++1y -I"/usr/include/R" -DNDEBUG -I"../inst/include" -I"`"/usr/lib64/R/bin/Rscript" --vanilla -e "cat(system.file('include', 'src', package = 'StanHeaders'))"`" -DBOOST_DISABLE_ASSERTS -DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION -I"/home/robka/R/Rcpp/include" -I"/home/robka/R/RcppEigen/include" -I"/home/robka/R/BH/include" -I"/home/robka/R/StanHeaders/include" -I/usr/local/include     -O3 -c lang__grammars__indexes_grammar_inst.cpp -o lang__grammars__indexes_grammar_inst.o
g++ -std=c++1y -I"/usr/include/R" -DNDEBUG -I"../inst/include" -I"`"/usr/lib64/R/bin/Rscript" --vanilla -e "cat(system.file('include', 'src', package = 'StanHeaders'))"`" -DBOOST_DISABLE_ASSERTS -DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION -I"/home/robka/R/Rcpp/include" -I"/home/robka/R/RcppEigen/include" -I"/home/robka/R/BH/include" -I"/home/robka/R/StanHeaders/include" -I/usr/local/include     -O3 -c lang__grammars__program_grammar_inst.cpp -o lang__grammars__program_grammar_inst.o
g++ -std=c++1y -I"/usr/include/R" -DNDEBUG -I"../inst/include" -I"`"/usr/lib64/R/bin/Rscript" --vanilla -e "cat(system.file('include', 'src', package = 'StanHeaders'))"`" -DBOOST_DISABLE_ASSERTS -DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION -I"/home/robka/R/Rcpp/include" -I"/home/robka/R/RcppEigen/include" -I"/home/robka/R/BH/include" -I"/home/robka/R/StanHeaders/include" -I/usr/local/include     -O3 -c lang__grammars__semantic_actions.cpp -o lang__grammars__semantic_actions.o
g++ -std=c++1y -I"/usr/include/R" -DNDEBUG -I"../inst/include" -I"`"/usr/lib64/R/bin/Rscript" --vanilla -e "cat(system.file('include', 'src', package = 'StanHeaders'))"`" -DBOOST_DISABLE_ASSERTS -DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION -I"/home/robka/R/Rcpp/include" -I"/home/robka/R/RcppEigen/include" -I"/home/robka/R/BH/include" -I"/home/robka/R/StanHeaders/include" -I/usr/local/include     -O3 -c lang__grammars__statement_2_grammar_inst.cpp -o lang__grammars__statement_2_grammar_inst.o
g++ -std=c++1y -I"/usr/include/R" -DNDEBUG -I"../inst/include" -I"`"/usr/lib64/R/bin/Rscript" --vanilla -e "cat(system.file('include', 'src', package = 'StanHeaders'))"`" -DBOOST_DISABLE_ASSERTS -DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION -I"/home/robka/R/Rcpp/include" -I"/home/robka/R/RcppEigen/include" -I"/home/robka/R/BH/include" -I"/home/robka/R/StanHeaders/include" -I/usr/local/include     -O3 -c lang__grammars__statement_grammar_inst.cpp -o lang__grammars__statement_grammar_inst.o
g++ -std=c++1y -I"/usr/include/R" -DNDEBUG -I"../inst/include" -I"`"/usr/lib64/R/bin/Rscript" --vanilla -e "cat(system.file('include', 'src', package = 'StanHeaders'))"`" -DBOOST_DISABLE_ASSERTS -DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION -I"/home/robka/R/Rcpp/include" -I"/home/robka/R/RcppEigen/include" -I"/home/robka/R/BH/include" -I"/home/robka/R/StanHeaders/include" -I/usr/local/include     -O3 -c lang__grammars__term_grammar_inst.cpp -o lang__grammars__term_grammar_inst.o
g++ -std=c++1y -I"/usr/include/R" -DNDEBUG -I"../inst/include" -I"`"/usr/lib64/R/bin/Rscript" --vanilla -e "cat(system.file('include', 'src', package = 'StanHeaders'))"`" -DBOOST_DISABLE_ASSERTS -DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION -I"/home/robka/R/Rcpp/include" -I"/home/robka/R/RcppEigen/include" -I"/home/robka/R/BH/include" -I"/home/robka/R/StanHeaders/include" -I/usr/local/include     -O3 -c lang__grammars__var_deccls_grammar_inst.cpp -o lang__grammars__var_deccls_grammar_inst.o
g++ -std=c++1y -I"/usr/include/R" -DNDEBUG -I"../inst/include" -I"`"/usr/lib64/R/bin/Rscript" --vanilla -e "cat(system.file('include', 'src', package = 'StanHeaders'))"`" -DBOOST_DISABLE_ASSERTS -DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION -I"/home/robka/R/Rcpp/include" -I"/home/robka/R/RcppEigen/include" -I"/home/robka/R/BH/include" -I"/home/robka/R/StanHeaders/include" -I/usr/local/include     -O3 -c lang__grammars__whitespace_grammar_inst.cpp -o lang__grammars__whitespace_grammar_inst.o
g++ -std=c++1y -I"/usr/include/R" -DNDEBUG -I"../inst/include" -I"`"/usr/lib64/R/bin/Rscript" --vanilla -e "cat(system.file('include', 'src', package = 'StanHeaders'))"`" -DBOOST_DISABLE_ASSERTS -DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION -I"/home/robka/R/Rcpp/include" -I"/home/robka/R/RcppEigen/include" -I"/home/robka/R/BH/include" -I"/home/robka/R/StanHeaders/include" -I/usr/local/include     -O3 -c misc.cpp -o misc.o
g++ -std=c++1y -I"/usr/include/R" -DNDEBUG -I"../inst/include" -I"`"/usr/lib64/R/bin/Rscript" --vanilla -e "cat(system.file('include', 'src', package = 'StanHeaders'))"`" -DBOOST_DISABLE_ASSERTS -DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION -I"/home/robka/R/Rcpp/include" -I"/home/robka/R/RcppEigen/include" -I"/home/robka/R/BH/include" -I"/home/robka/R/StanHeaders/include" -I/usr/local/include     -O3 -c pointer-tools.cpp -o pointer-tools.o
In file included from /home/robka/R/BH/include/boost/random/detail/integer_log2.hpp:19:0,
                 from /home/robka/R/BH/include/boost/random/detail/large_arithmetic.hpp:19,
                 from /home/robka/R/BH/include/boost/random/detail/const_mod.hpp:23,
                 from /home/robka/R/BH/include/boost/random/linear_congruential.hpp:30,
                 from /home/robka/R/BH/include/boost/random/additive_combine.hpp:27,
                 from pointer-tools.cpp:2:
/home/robka/R/BH/include/boost/pending/integer_log2.hpp:7:89: note: #pragma message: This header is deprecated. Use <boost/integer/integer_log2.hpp> instead.
 BOOST_HEADER_DEPRECATED("<boost/integer/integer_log2.hpp>");
                                                                                         ^
g++ -std=c++1y -I"/usr/include/R" -DNDEBUG -I"../inst/include" -I"`"/usr/lib64/R/bin/Rscript" --vanilla -e "cat(system.file('include', 'src', package = 'StanHeaders'))"`" -DBOOST_DISABLE_ASSERTS -DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION -I"/home/robka/R/Rcpp/include" -I"/home/robka/R/RcppEigen/include" -I"/home/robka/R/BH/include" -I"/home/robka/R/StanHeaders/include" -I/usr/local/include     -O3 -c sparse_extractors.cpp -o sparse_extractors.o
g++ -std=c++1y -I"/usr/include/R" -DNDEBUG -I"../inst/include" -I"`"/usr/lib64/R/bin/Rscript" --vanilla -e "cat(system.file('include', 'src', package = 'StanHeaders'))"`" -DBOOST_DISABLE_ASSERTS -DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION -I"/home/robka/R/Rcpp/include" -I"/home/robka/R/RcppEigen/include" -I"/home/robka/R/BH/include" -I"/home/robka/R/StanHeaders/include" -I/usr/local/include     -O3 -c stanc.cpp -o stanc.o
g++ -std=c++1y -shared -L/usr/lib64/R/lib -Wl,-z,relro -o rstan.so chains.o init.o lang__ast_def.o lang__grammars__bare_type_grammar_inst.o lang__grammars__expression07_grammar_inst.o lang__grammars__expression_grammar_inst.o lang__grammars__functions_grammar_inst.o lang__grammars__indexes_grammar_inst.o lang__grammars__program_grammar_inst.o lang__grammars__semantic_actions.o lang__grammars__statement_2_grammar_inst.o lang__grammars__statement_grammar_inst.o lang__grammars__term_grammar_inst.o lang__grammars__var_deccls_grammar_inst.o lang__grammars__whitespace_grammar_inst.o misc.o pointer-tools.o sparse_extractors.o stanc.o -L/usr/lib64/R/lib -lR
/usr/bin/ld: chains.o: relocation R_X86_64_32 against hidden symbol `_ZGVZ7dataptrP7SEXPRECE3fun' can not be used when making a shared object
/usr/bin/ld: init.o: relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: lang__ast_def.o: relocation R_X86_64_32S against `.rodata' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: lang__grammars__bare_type_grammar_inst.o: relocation R_X86_64_32 against symbol `_ZN5boost9function4IbRNS_6spirit17line_pos_iteratorIN9__gnu_cxx17__normal_iteratorIPKcSsEEEERKS8_RNS1_7contextINS_6fusion4consIRNS1_11unused_typeENSD_4nil_EEENSD_6vectorIIEEEEERKSF_E5dummy7nonnullEv' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: lang__grammars__expression07_grammar_inst.o: relocation R_X86_64_32 against `.rodata.str1.8' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: lang__grammars__expression_grammar_inst.o: relocation R_X86_64_32 against symbol `_ZN5boost9function4IbRNS_6spirit17line_pos_iteratorIN9__gnu_cxx17__normal_iteratorIPKcSsEEEERKS8_RNS1_7contextINS_6fusion4consIRNS1_11unused_typeENSD_4nil_EEENSD_6vectorIIEEEEERKSF_E5dummy7nonnullEv' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: lang__grammars__functions_grammar_inst.o: relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: lang__grammars__indexes_grammar_inst.o: relocation R_X86_64_32 against symbol `_ZN5boost9function4IbRNS_6spirit17line_pos_iteratorIN9__gnu_cxx17__normal_iteratorIPKcSsEEEERKS8_RNS1_7contextINS_6fusion4consIRNS1_11unused_typeENSD_4nil_EEENSD_6vectorIIEEEEERKSF_E5dummy7nonnullEv' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: lang__grammars__program_grammar_inst.o: relocation R_X86_64_32 against symbol `_ZN5boost9function4IbRNS_6spirit17line_pos_iteratorIN9__gnu_cxx17__normal_iteratorIPKcSsEEEERKS8_RNS1_7contextINS_6fusion4consIRNS1_11unused_typeENSD_4nil_EEENSD_6vectorIIEEEEERKSF_E5dummy7nonnullEv' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: lang__grammars__semantic_actions.o: relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: lang__grammars__statement_2_grammar_inst.o: relocation R_X86_64_32 against symbol `_ZN5boost9function4IbRNS_6spirit17line_pos_iteratorIN9__gnu_cxx17__normal_iteratorIPKcSsEEEERKS8_RNS1_7contextINS_6fusion4consIRNS1_11unused_typeENSD_4nil_EEENSD_6vectorIIEEEEERKSF_E5dummy7nonnullEv' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: lang__grammars__statement_grammar_inst.o: relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: lang__grammars__term_grammar_inst.o: relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: lang__grammars__var_deccls_grammar_inst.o: relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: lang__grammars__whitespace_grammar_inst.o: relocation R_X86_64_32S against symbol `_ZTIN5boost6spirit2qi6detail13parser_binderINS1_11alternativeINS_6fusion4consINS1_15expect_operatorINS6_INS1_8sequenceINS6_INS1_14omit_directiveINS1_14literal_stringIRA3_KcLb1EEEEENS6_INS1_6kleeneINS1_10differenceINS1_10char_classINS0_3tag9char_codeINSJ_5char_ENS0_13char_encoding8standardEEEEESE_EEEENS5_4nil_EEEEEEENS6_ISF_SS_EEEEEENS6_INS8_INS6_ISF_NS6_INSG_INSH_ISP_NS1_10eol_parserEEEEESS_EEEEEENS6_INS1_6actionINS8_INS6_INS9_INS1_12literal_charISN_Lb1ELb0EEEEES12_EEEENS_7phoenix5actorINS_5proto7exprns_10basic_exprINS1B_6detail3tag13function_evalENS1D_7argsns_5list2INS1F_INS1D_6tagns_3tag8terminalENS1J_4termIN4stan4lang23deprecate_pound_commentEEELl0EEENS1C_INS1F_IS1N_NS1O_INS_17reference_wrapperISt18basic_stringstreamIcSt11char_traitsIcESaIcEEEEEELl0EEEEEEELl2EEEEEEENS6_INSI_INSK_INSJ_5spaceENSM_5asciiEEEEESS_EEEEEEEEEEN4mpl_5bool_ILb0EEEEE' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: pointer-tools.o: relocation R_X86_64_32 against `.bss' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: sparse_extractors.o: relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: stanc.o: relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Nonrepresentable section on output
collect2: error: ld returned 1 exit status
make: *** [rstan.so] Error 1
ERROR: compilation failed for package ‘rstan’
* removing ‘/home/robka/R/rstan’

The downloaded source packages are in
	‘/tmp/RtmpaR03U1/downloaded_packages’
Warning message:
In install.packages("rstan") :
  installation of package ‘rstan’ had non-zero exit status

I’m not used to CentOS nor do I work with C/C++/gcc/g++/ so I’m pretty much in over my head and my only crime is that I want R to install ‘rstan’ and then ‘brms’.

I did find this but did not dare to try it without consultation:

dotR <- file.path(Sys.getenv("HOME"), ".R")
if (!file.exists(dotR)) dir.create(dotR)
M <- file.path(dotR, ifelse(.Platform$OS.type == "windows", "Makevars.win", "Makevars"))
if (!file.exists(M)) file.create(M)
cat("\nCXX14FLAGS=-O3 -march=native -mtune=native",
    if( grepl("^darwin", R.version$os)) "CXX14FLAGS += -arch x86_64 -ftemplate-depth-256" else 
    if (.Platform$OS.type == "windows") "CXX11FLAGS=-O3 -march=native -mtune=native" else
    "CXX14FLAGS += -fPIC",
    file = M, sep = "\n", append = TRUE)

Can anyone cast some light on this? I would be forever great-full. If not, I will have to re-install the computer with Ubuntu and that would be a hassle for my other projects…

Thanks in advance and please excuse any format errors, first time poster!

EDIT: After trying different combinations of settings in the Makeconf file it worked! No idea why these particular settings worked. Here are the things I added:

CXX14 = g++ -fPIC
CXX14FLAGS = -O3
CXX14PICFLAGS = -fpic
CXX14STD = -std=gnu++1y

Only when I added the -fPIC to CXX14 and CXX14PICFLAGS did it work. If you want this to post to be saved and marked as solved, please do so. If not you can remove it or tell me to remove it. Thanks anyway!

Still wonder why I did not have a Makevars file under ~/R/ and why my changes to ~/R/RcppEigen/skeleton/Makevars did not take. And why these particular Makeconf settings worked.

Robin


#2

This is probably going to sound annoying after all the time you spent trying different combinations of things, but the settings you landed on are basically those documented for Linux in the wiki:

That is a user-configuration file (or it should be if there was actually a period before the R). This is explained at

https://cran.r-project.org/doc/manuals/r-release/R-admin.html#Customizing-package-compilation

That is a package-specific configuration file, so even if you edited it in an admissible fashion it would only apply to the RcppEigen package and not the rstan package.


#3

Thanks for clearing that out!

I guess this is solved.

Best,
Robin