# RStan unable to find g++ when compiling model

**URL:** <https://discourse.mc-stan.org/t/rstan-unable-to-find-g-when-compiling-model/574>\
**Category:** RStan\
**Created:** [May 16, 2017, 11:19pm UTC](https://discourse.mc-stan.org/t/rstan-unable-to-find-g-when-compiling-model/574 "2017-05-16T23:19:59Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![ben.fotovich](https://avatars.discourse-cdn.com/v4/letter/b/7993a0/32.png) [@ben.fotovich](https://discourse.mc-stan.org/u/ben.fotovich)\
**Post date:** [May 16, 2017, 11:19pm UTC](https://discourse.mc-stan.org/t/rstan-unable-to-find-g-when-compiling-model/574/1 "2017-05-16T23:19:59Z")

</div>

Hello,

We are trying to run a computation, with RStan, but when the job is submitted, it fails when compiling the model, with the below error message:

```
Error in compileCode(f, code, language = language, verbose = verbose) :
  Compilation ERROR, function(s)/method(s) not created! /bin/sh: /bin/g++: No such file or directory
make: *** [file3843752b0cf6.o] Error 127
Calls: brm ... <Anonymous> -> cxxfunctionplus -> cxxfunction -> compileCode
In addition: Warning message:
running command '/usr/local/R/3.4.0/lib64/R/bin/R CMD SHLIB file3843752b0cf6.cpp 2> file3843752b0cf6.cpp.err.txt' had status 1
Execution halted

```

I’ve found suggested solutions, but they only apply to Rtools, and this issue is happening on RHEL 7.3.

Am I missing something obvious? Please see below for additional details and please let me know what additional information I can provide.

Thanks for any insight or direction you can offer!

* * *

R 3.4.0 (compiled, not installed via package manager)  
RStan 2.15.1 (installed via installed.packages(“rstan”))

Inside of R, the output from “system(‘which g++’)” is:

> /usr/bin/g++

The output from “system(‘g++ -v’)” is:

> Using built-in specs.  
> COLLECT\_GCC=g++  
> COLLECT\_LTO\_WRAPPER=/usr/libexec/gcc/x86\_64-redhat-linux/4.8.5/lto-wrapper  
> Target: x86\_64-redhat-linux  
> Configured with: …/configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=[http://bugzilla.redhat.com/bugzilla](http://bugzilla.redhat.com/bugzilla) --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-\_\_cxa\_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto --enable-plugin --enable-initfini-array --disable-libgcj --with-isl=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86\_64-redhat-linux/isl-install --with-cloog=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86\_64-redhat-linux/cloog-install --enable-gnu-indirect-function --with-tune=generic --with-arch\_32=x86-64 --build=x86\_64-redhat-linux  
> Thread model: posix  
> gcc version 4.8.5 20150623 (Red Hat 4.8.5-11) (GCC)

Contents of ~/.R/Makevars:

> CXX = /bin/g++  
> CC = /bin/gcc  
> FC = /bin/gfortran

Output from env, from the terminal, is:

> MODULE\_VERSION\_STACK=3.2.10  
> MANPATH=/usr/local/gdal/2.1.3/share/gdal:/usr/local/proj/4.9.3/share/man:/usr/local/curl/7.53.1/share/man:/usr/local/openmpi/1.10.6/gnu/4.8.5-rhel/ib/man:/usr/local/Modules/3.2.10/share/man:/opt/sge/man:/usr/share/man/overrides:/usr/share/man:/usr/local/share/man  
> XDG\_SESSION\_ID=30771  
> HOSTNAME=du-hpc  
> TERM=xterm  
> SHELL=/bin/bash  
> HISTSIZE=1000  
> SSH\_CLIENT= 22  
> PERL5LIB=/usr/lib64/perl5  
> SGE\_CELL=default  
> SGE\_ARCH=lx-amd64  
> OPTS=-O3  
> QTDIR=/usr/lib64/qt-3.3  
> OLDPWD=/home/bfotovic/.R  
> QTINC=/usr/lib64/qt-3.3/include  
> SSH\_TTY=/dev/pts/5  
> QT\_GRAPHICSSYSTEM\_CHECKED=1  
> USER=bfotovic  
> LD\_LIBRARY\_PATH=/usr/local/R/3.4.0/lib64:/usr/local/gdal/2.1.3/lib:/usr/local/proj/4.9.3/lib:/usr/local/curl/7.53.1/lib:/usr/local/lapack/3.7.0/lib:/usr/local/blas/3.7.0/lib:/usr/local/geos/3.6.1/lib:/usr/local/openmpi/1.10.6/gnu/4.8.5-rhel/ib/lib  
> LS\_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=01;05;37;41:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:_.tar=01;31:_.tgz=01;31:_.arc=01;31:_.arj=01;31:_.taz=01;31:_.lha=01;31:_.lz4=01;31:_.lzh=01;31:_.lzma=01;31:_.tlz=01;31:_.txz=01;31:_.tzo=01;31:_.t7z=01;31:_.zip=01;31:_.z=01;31:_.Z=01;31:_.dz=01;31:_.gz=01;31:_.lrz=01;31:_.lz=01;31:_.lzo=01;31:_.xz=01;31:_.bz2=01;31:_.bz=01;31:_.tbz=01;31:_.tbz2=01;31:_.tz=01;31:_.deb=01;31:_.rpm=01;31:_.jar=01;31:_.war=01;31:_.ear=01;31:_.sar=01;31:_.rar=01;31:_.alz=01;31:_.ace=01;31:_.zoo=01;31:_.cpio=01;31:_.7z=01;31:_.rz=01;31:_.cab=01;31:_.jpg=01;35:_.jpeg=01;35:_.gif=01;35:_.bmp=01;35:_.pbm=01;35:_.pgm=01;35:_.ppm=01;35:_.tga=01;35:_.xbm=01;35:_.xpm=01;35:_.tif=01;35:_.tiff=01;35:_.png=01;35:_.svg=01;35:_.svgz=01;35:_.mng=01;35:_.pcx=01;35:_.mov=01;35:_.mpg=01;35:_.mpeg=01;35:_.m2v=01;35:_.mkv=01;35:_.webm=01;35:_.ogm=01;35:_.mp4=01;35:_.m4v=01;35:_.mp4v=01;35:_.vob=01;35:_.qt=01;35:_.nuv=01;35:_.wmv=01;35:_.asf=01;35:_.rm=01;35:_.rmvb=01;35:_.flc=01;35:_.avi=01;35:_.fli=01;35:_.flv=01;35:_.gl=01;35:_.dl=01;35:_.xcf=01;35:_.xwd=01;35:_.yuv=01;35:_.cgm=01;35:_.emf=01;35:_.axv=01;35:_.anx=01;35:_.ogv=01;35:_.ogx=01;35:_.aac=01;36:_.au=01;36:_.flac=01;36:_.mid=01;36:_.midi=01;36:_.mka=01;36:_.mp3=01;36:_.mpc=01;36:_.ogg=01;36:_.ra=01;36:_.wav=01;36:_.axa=01;36:_.oga=01;36:_.spx=01;36:\*.xspf=01;36:  
> MODULE\_VERSION=3.2.10  
> MAIL=/var/spool/mail/bfotovic  
> PATH=/usr/local/R/3.4.0/bin:/usr/local/gdal/2.1.3/bin:/usr/local/proj/4.9.3/bin:/usr/local/curl/7.53.1/bin:/usr/local/geos/3.6.1/bin:/usr/local/openmpi/1.10.6/gnu/4.8.5-rhel/ib/bin:/usr/local/Modules/3.2.10/bin:/opt/sge/bin:/opt/sge/bin/lx-amd64:/usr/lib64/qt-3.3/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/opt/puppetlabs/bin:/home/bfotovic/bin  
> PWD=/home/bfotovic  
> _LMFILES_=/usr/local/Modules/modulefiles/null:/usr/local/Modules/modulefiles/modules:/usr/local/Modules/modulefiles/mpi/openmpi-1.10.6-gcc4.8.5:/usr/local/Modules/modulefiles/tools/geos-3.6.1:/usr/local/Modules/modulefiles/libs/blas-3.7.0:/usr/local/Modules/modulefiles/libs/lapack-3.7.0:/usr/local/Modules/modulefiles/tools/curl-7.53.1:/usr/local/Modules/modulefiles/tools/proj-4.9.3:/usr/local/Modules/modulefiles/tools/gdal-2.1.3:/usr/local/Modules/modulefiles/apps/R-3.4.0  
> SGE\_EXECD\_PORT=6445  
> LANG=en\_US.UTF-8  
> MODULEPATH=/usr/local/Modules/versions:/usr/local/Modules/$MODULE\_VERSION/modulefiles:/usr/local/Modules/modulefiles  
> SGE\_QMASTER\_PORT=6444  
> LOADEDMODULES=null:modules:mpi/openmpi-1.10.6-gcc4.8.5:tools/geos-3.6.1:libs/blas-3.7.0:libs/lapack-3.7.0:tools/curl-7.53.1:tools/proj-4.9.3:tools/gdal-2.1.3:apps/R-3.4.0  
> SGE\_ROOT=/opt/sge  
> HISTCONTROL=ignoredups  
> SHLVL=1  
> HOME=/home/bfotovic  
> MATHEMATICA\_HOME=/usr/local/mathematica/11.1  
> PYTHONPATH=/usr/lib64/python2.7  
> LOGNAME=bfotovic  
> QTLIB=/usr/lib64/qt-3.3/lib  
> SSH\_CONNECTION=130.253.15.56 37074 130.253.21.117 22  
> GXX\_ROOT=/usr/lib/gcc/x86\_64-redhat-linux/4.8.5  
> MODULESHOME=/usr/local/Modules/3.2.10  
> LESSOPEN=||/usr/bin/lesspipe.sh %s  
> SGE\_CLUSTER\_NAME=p6444  
> XDG\_RUNTIME\_DIR=/run/user/565  
> DISPLAY=localhost:13.0  
> INCLUDE=/usr/local/gdal/2.1.3/include:/usr/local/proj/4.9.3/include:/usr/local/curl/7.53.1/include:/usr/local/geos/3.6.1/include  
> BASH\_FUNC\_module()=() { eval `/usr/local/Modules/$MODULE_VERSION/bin/modulecmd bash $*`  
> }  
> \_=/usr/bin/env

---

<div class="post-metadata">

**Author:** ![bgoodri](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/bgoodri/32/4451_2.png) [@bgoodri](https://discourse.mc-stan.org/u/bgoodri)\
**Post date:** [May 17, 2017, 1:32am UTC](https://discourse.mc-stan.org/t/rstan-unable-to-find-g-when-compiling-model/574/2 "2017-05-17T01:32:52Z")

</div>

This

> [@ben.fotovich](#):
>
> Inside of R, the output from “system(‘which g++’)” is:
> 
> /usr/bin/g++

does not match with

> [@ben.fotovich](#):
>
> Contents of ~/.R/Makevars:
> 
> CXX = /bin/g++  
> CC = /bin/gcc  
> FC = /bin/gfortran

You should probably just have

```no-highlight
CXX=g++
CC=gcc
FC=gfortran

```

---

<div class="post-metadata">

**Author:** ![ben.fotovich](https://avatars.discourse-cdn.com/v4/letter/b/7993a0/32.png) [@ben.fotovich](https://discourse.mc-stan.org/u/ben.fotovich)\
**Post date:** [May 17, 2017, 5:38pm UTC](https://discourse.mc-stan.org/t/rstan-unable-to-find-g-when-compiling-model/574/3 "2017-05-17T17:38:41Z")

</div>

Hey bgoodri,

Thanks for the suggestion!

I made the change to ~/.R/Makevars:

> CXX=g++  
> CC=gcc  
> FC=gfortran

And we’re still getting the same error message.

What additional steps could/should I attempt?

Thanks!

---

<div class="post-metadata">

**Author:** ![bgoodri](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/bgoodri/32/4451_2.png) [@bgoodri](https://discourse.mc-stan.org/u/bgoodri)\
**Post date:** [May 17, 2017, 11:55pm UTC](https://discourse.mc-stan.org/t/rstan-unable-to-find-g-when-compiling-model/574/4 "2017-05-17T23:55:14Z")

</div>

You mean it now says  
`Compilation ERROR, function(s)/method(s) not created! /bin/sh: /usr/bin/g++: No such file or directory`

---

<div class="post-metadata">

**Author:** ![ben.fotovich](https://avatars.discourse-cdn.com/v4/letter/b/7993a0/32.png) [@ben.fotovich](https://discourse.mc-stan.org/u/ben.fotovich)\
**Post date:** [May 19, 2017, 5:05pm UTC](https://discourse.mc-stan.org/t/rstan-unable-to-find-g-when-compiling-model/574/5 "2017-05-19T17:05:26Z")

</div>

Sorry for my slow response.

Here is the error message now:

> Error in compileCode(f, code, language = language, verbose = verbose) :  
> Compilation ERROR, function(s)/method(s) not created! /bin/sh: g++: command not found  
> make: \*\*\* [file56907e8d301d.o] Error 127  
> Calls: brm … → cxxfunctionplus → cxxfunction → compileCode  
> In addition: Warning message:  
> running command ‘/usr/local/R/3.4.0/lib64/R/bin/R CMD SHLIB file56907e8d301d.cpp 2\> file56907e8d301d.cpp.err.txt’ had status 1  
> Execution halted

Thanks!

---

<div class="post-metadata">

**Author:** ![bgoodri](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/bgoodri/32/4451_2.png) [@bgoodri](https://discourse.mc-stan.org/u/bgoodri)\
**Post date:** [May 19, 2017, 5:17pm UTC](https://discourse.mc-stan.org/t/rstan-unable-to-find-g-when-compiling-model/574/6 "2017-05-19T17:17:47Z")

</div>

My guess is that the `PATH` of the worker that compiles the Stan model is not the same as the `PATH` in the output of `env`. Do you get more information in the log if you call `stan_model` with `verbose = TRUE`?

---

<div class="post-metadata">

**Author:** ![ben.fotovich](https://avatars.discourse-cdn.com/v4/letter/b/7993a0/32.png) [@ben.fotovich](https://discourse.mc-stan.org/u/ben.fotovich)\
**Post date:** [May 22, 2017, 4:02pm UTC](https://discourse.mc-stan.org/t/rstan-unable-to-find-g-when-compiling-model/574/7 "2017-05-22T16:02:24Z")

</div>

I haven’t tried your suggestion (though I can compile R and packages, using it is something I’m still learning, along with researchers I assist), but I want to share some behavior:

The error I encountered appears when trying to run the R analysis through a job queue system; submission script calls Rscript .

When I run R and enter the commands directly, _everything_ works, including the compilation of the stan model. So, from what I can tell, there seems to be a pathing challenge when calling Rscript.

If you have any advice for this, please let me know, but I think the issue may exist outside of your package.

Thank you for your patience and assistance!

---

<div class="post-metadata">

**Author:** ![ben.fotovich](https://avatars.discourse-cdn.com/v4/letter/b/7993a0/32.png) [@ben.fotovich](https://discourse.mc-stan.org/u/ben.fotovich)\
**Post date:** [May 22, 2017, 4:14pm UTC](https://discourse.mc-stan.org/t/rstan-unable-to-find-g-when-compiling-model/574/8 "2017-05-22T16:14:27Z")

</div>

Indeed, there was a path issue, on some of the nodes we tried to run a stan model with. After it was corrected, the stan model compiles consistently every time!

---

<div class="post-metadata">

**Author:** ![bgoodri](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/bgoodri/32/4451_2.png) [@bgoodri](https://discourse.mc-stan.org/u/bgoodri)\
**Post date:** [May 22, 2017, 4:18pm UTC](https://discourse.mc-stan.org/t/rstan-unable-to-find-g-when-compiling-model/574/9 "2017-05-22T16:18:35Z")

</div>

Ahh, now you tell me. RStan has been known to not work with Rscript for reasons that are both mysterious and beyond our control, although I can’t remember it manifesting itself in failing to find the compiler. Usually the problem is that you have to call `library(Rcpp)` explicitly in the script or specify --default-packages=Rcpp. But with either of those, I can compile Stan programs on my machine. Are you sure the Rscript that is being called is on the same filesystem as the one where g++ is installed?

---

<div class="post-metadata">

**Author:** ![ben.fotovich](https://avatars.discourse-cdn.com/v4/letter/b/7993a0/32.png) [@ben.fotovich](https://discourse.mc-stan.org/u/ben.fotovich)\
**Post date:** [May 22, 2017, 5:08pm UTC](https://discourse.mc-stan.org/t/rstan-unable-to-find-g-when-compiling-model/574/10 "2017-05-22T17:08:17Z")

</div>

To answer your question: as g++ didn’t exist, on the compute nodes, g++ and Rscript weren’t on the same file system.

On the compute nodes, R wasn’t able to find g++, but on the head node, it was. The “path issue” was that a g++ package wasn’t explicitly installed, on the compute nodes. After installing the g++ package, everything worked correctly.

Thank you!
