Error in compileCode(f, code, langu> age = language, verbose = verbose) in CentOS 7.6

Operating System: CentOS7.6

Interface Version: R version 3.6.0 (2019-04-26) – “Planting of a Tree”
Copyright © 2019 The R Foundation for Statistical Computing
Platform: x86_64-redhat-linux-gnu (64-bit)

Compiler/Toolkit: g++


When I run “stan_model” to compile stan file, the following error comes.
I found similar topics online and tried various versions of “Makevars”, but still facing the error.

What can I do?
Thank you.

Error in compileCode(f, code, langu> age = language, verbose = verbose) :
Compilation ERROR, function(s)/method(s) not created! In file included from /home/changy/R/x86_64-redhat-linux-gnu-library/3.6/BH/include/boost/random/detail/integer_log2.hpp:19:0,
from /home/changy/R/x86_64-redhat-linux-gnu-library/3.6/BH/include/boost/random/detail/int_float_pair.hpp:26,
from /home/changy/R/x86_64-redhat-linux-gnu-library/3.6/BH/include/boost/random/exponential_distribution.hpp:27,
from /home/changy/R/x86_64-redhat-linux-gnu-library/3.6/BH/include/boost/random/gamma_distribution.hpp:25,
from /home/changy/R/x86_64-redhat-linux-gnu-library/3.6/StanHeaders/include/stan/math/prim/mat/prob/dirichlet_rng.hpp:5,
from /home/changy/R/x86_64-redhat-linux-gnu-library/3.6/StanHeaders/include/stan/math/prim/mat.hpp:292,
from /home/changy/R/x86_64-redhat-linux-gnu-library/3.6/StanHeaders/include/stan/math/rev/mat.hpp:12,
from /home/changy/R/x86_64-redhat
In addition: Warning message:
In system(cmd, intern = !verbose) :
running command ‘/usr/lib64/R/bin/R CMD SHLIB file21352db2fbc.cpp 2> file21352db2fbc.cpp.err.txt’ had status 1
Error in sink(type = “output”) : invalid connection

We need to see the error message when the verbose = TRUE argument is specified, but my guess is that your g++ is too old to implment the necessary parts of the C++14 standard.

I have implemented the following three lines in CentOS, such that “g++ --version” returns
“g++ (GCC) 7.3.1 20180303 (Red Hat 7.3.1-5)”

sudo yum install centos-release-scl
sudo yum install devtoolset-7
scl enable devtoolset-7 bash

However, after shutting off and turning on again, “g++ --version” goes back to
“g++ (GCC) 4.8.5 20150623 (Red Hat 4.8.5-36)”, so I run the three lines again to raise to g++ 7.3.1.

In the Rserver interface corresponding to the CentOS (cloud computing at school), I debugged stan file via

BLCA.stan.model=stan_model(
file=“BLCA_unconstrained_Givens_fixC_noZ.stan”,
model_name=“BLCA_unconstrained_Givens_fixC_noZ”,auto_write=T,verbose=T)

Then the following error returns:

The error is very long, and more is seen in the attached pdf.

Thank you very much.
Error message from stan_model.pdf (104.0 KB)

It chopped off the relevant part, but it is almost surely trying to use the older g++. You may need to put CXX14 = g++-7 or something in the ~/.R/Makevars file.

I edited my Makevars into (There is no space between “g++” and “-7”, I made a space here otherwise it becomes ±)

CXX14FLAGS=-O3 -march=native -mtune=native -fPIC
CXX14 = g++ -7

Now the error says:

Error in compileCode(f, code, language = language, verbose = verbose) :
Compilation ERROR, function(s)/method(s) not created! /bin/sh: g++ -7: command not found
make: *** [file5bbaefce1e.o] Error 127

By the way, the complete error message is attached.
Thanks.
complete error message.pdf (260.0 KB)

Another important information:

“rstan” works well this June on R-server on the school cloud computing with CentOS 7.6. Now I use the same way and get the error. Maybe something changed in the CentOS?

Well, it needs to be whatever the executable is called that has a later version of g++. You might also need to supply a full path, something like

CXX14 = /opt/useful_stuff/g++

I exactly typed in what you said

CXX14 = /opt/useful_stuff/g++

The error comes:

Error in compileCode(f, code, language = language, verbose = verbose) :
Compilation ERROR, function(s)/method(s) not created! /bin/sh: /opt/useful_stuff/g++: No such file or directory
make: *** [file5bb3a680c11.o] Error 127

How can I find out the full path of g++?

First try g++ -v: this will print out (among other things) the version it’s finding by default. The path to that can be found with which g++.

If you have more than one version installed, it’s possible (if CentOS behaves like Ubuntu) that they are called g++-5, g++-7 and so on. If those are the names and you want g+±7, its path is which g++-7.

/opt/useful_stuff/g++ was just an example. You may need the full path to wherever the good version of g++ is installed.

The output from “ system ('which g++ ')” is: /usr/bin/ g++. So my Makevars changes into

CXX14FLAGS=-O3 -march=native -mtune=native -fPIC
CXX14 = /usr/bin/g++

The error (red words) still comes

Error in compileCode(f, code, language = language, verbose = verbose) :
Compilation ERROR, function(s)/method(s) not created! In file included from /usr/include/c++/4.8.2/type_traits:35:0,
from /home/changy/R/x86_64-redhat-linux-gnu-library/3.6/StanHeaders/include/stan/math/prim/scal/meta/is_constant.hpp:4,
from /home/changy/R/x86_64-redhat-linux-gnu-library/3.6/StanHeaders/include/stan/math/prim/arr/meta/is_constant_struct.hpp:4,
from /home/changy/R/x86_64-redhat-linux-gnu-library/3.6/StanHeaders/include/stan/math/prim/mat/meta/is_constant_struct.hpp:4,
from /home/changy/R/x86_64-redhat-linux-gnu-library/3.6/StanHeaders/include/stan/math/prim/mat.hpp:15,
from /home/changy/R/x86_64-redhat-linux-gnu-library/3.6/StanHeaders/include/stan/math/rev/mat.hpp:12,
from /home/changy/R/x86_64-redhat-linux-gnu-library/3.6/StanHeaders/include/stan/math.hpp:4,
from /home/changy/R/x86_64-redhat-linux-gnu-library/3.6/StanHeaders/include/src/stan

Attach the complete error message.
complete error message 2.pdf (259.4 KB)

You are still using the g++ version 4.8.2. If you have installed a more recent version, put the path to that version in your Makevars, which you can find for example by doing which g++-7 if that’s what’s called on your system (an autocompletion on the Linux terminal might help you, so type g++ then press tab a couple of times to see what other executables start with that name).

Now I resolved this problem by the following way:

In CentOS 7.6, run the following 3 lines to install g++ 7.3.1

sudo yum install centos-release-scl
sudo yum install devtoolset-7
scl enable devtoolset-7 bash

“which g++ -7” cannot work but “which g++” gives

/opt/rh/devtoolset-7/root/usr/bin/g++

So I wrote down the following in my Makevars and now it works!

CXX14FLAGS=-O3 -march=native -mtune=native -fPIC
CXX14 = /opt/rh/devtoolset-7/root/usr/bin/g++ -std=c++1y

Thank you very much.