# G++ Compile Error With R Package

**URL:** <https://discourse.mc-stan.org/t/g-compile-error-with-r-package/10628>\
**Category:** RStan\
**Tags:** rstan\
**Created:** [August 27, 2019, 6:20pm UTC](https://discourse.mc-stan.org/t/g-compile-error-with-r-package/10628 "2019-08-27T18:20:57Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![decision-sciences](https://avatars.discourse-cdn.com/v4/letter/d/91b2a8/32.png) [@decision-sciences](https://discourse.mc-stan.org/u/decision-sciences)\
**Post date:** [August 27, 2019, 6:20pm UTC](https://discourse.mc-stan.org/t/g-compile-error-with-r-package/10628/1 "2019-08-27T18:20:58Z")

</div>

Hi all,

I’m trying to install an R package on my windows 10 PC that includes Rstan. I did not build the package myself (it was built on mac). Though the package installs fine on mac:

devtools::install\_github(“ColumbiaCDS/DEEPEst”,force = TRUE)

I get this output on PC:

C:/RBuildTools/3.5/mingw\_32/bin/g++ -m32g -std=c++1y -I"C:/PROGRA~1/R/R-36~1.1/include" -DNDEBUG -I"…/inst/include" -I"C:/Users/np2730/Documents/R/win-library/3.6/StanHeaders/include/src" -DBOOST\_DISABLE\_ASSERTS -DEIGEN\_NO\_DEBUG -I"C:/Users/np2730/Documents/R/win-library/3.6/BH/include" -I"C:/Users/np2730/Documents/R/win-library/3.6/Rcpp/include" -I"C:/Users/np2730/Documents/R/win-library/3.6/RcppEigen/include" -I"C:/Users/np2730/Documents/R/win-library/3.6/rstan/include" -I"C:/Users/np2730/Documents/R/win-library/3.6/StanHeaders/include" -O3 -Wno-unused-variable -Wno-unused-function -c RcppExports.cpp -o RcppExports.o  
g++.exe: error: unrecognized command line option ‘-m32g’  
make: \*\*\* [C:/PROGRA~1/R/R-36~1.1/etc/i386/Makeconf:215: RcppExports.o] Error 1  
ERROR: compilation failed for package ‘DEEPEst’

I believe this issue has something to do with the compiler being used: on Mac, where the installation works fine, it mentions clang as the compiler instead of g++. I know practically nothing about C, so any insight anyone has would be really appreciated. I’m happy to provide any other information that I might have left out. I’m using R version 3.6.1 and rstan version 2.19.2.

---

<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:** [August 28, 2019, 2:12am UTC](https://discourse.mc-stan.org/t/g-compile-error-with-r-package/10628/2 "2019-08-28T02:12:20Z")

</div>

You need a space in your ~/.R/Makevars.win file before the `g`, but actually you should just omit the debug info by putting `-g0`.

---

<div class="post-metadata">

**Author:** ![decision-sciences](https://avatars.discourse-cdn.com/v4/letter/d/91b2a8/32.png) [@decision-sciences](https://discourse.mc-stan.org/u/decision-sciences)\
**Post date:** [August 28, 2019, 4:03pm UTC](https://discourse.mc-stan.org/t/g-compile-error-with-r-package/10628/3 "2019-08-28T16:03:57Z")

</div>

Thanks for responding!

I’m sorry if I’m missing something–I can’t find an ~/.R/Makevars.win file. I found a makevars.win file in ~/src/Makevars.win file–here’s the text:

```
STANHEADERS_SRC = $(shell "$(R_HOME)/bin$(R_ARCH_BIN)/Rscript" -e "message()" -e "cat(system.file('include', 'src', package = 'StanHeaders', mustWork = TRUE))" -e "message()" | grep "StanHeaders")

PKG_CPPFLAGS = -I"../inst/include" -I"$(STANHEADERS_SRC)" -DBOOST_DISABLE_ASSERTS -DEIGEN_NO_DEBUG

CXX_STD = CXX14

all: $(SHLIB)

clean:
		RM -rf *.so *.o

.phony: all clean

```

Which g are you referring to that I should put a space in front of?

Thanks again for helping!

---

<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:** [August 28, 2019, 6:33pm UTC](https://discourse.mc-stan.org/t/g-compile-error-with-r-package/10628/4 "2019-08-28T18:33:36Z")

</div>

That is the Makevars file for **rstanarm**. I would just delete it and then it might work.

---

<div class="post-metadata">

**Author:** ![decision-sciences](https://avatars.discourse-cdn.com/v4/letter/d/91b2a8/32.png) [@decision-sciences](https://discourse.mc-stan.org/u/decision-sciences)\
**Post date:** [September 9, 2019, 4:07pm UTC](https://discourse.mc-stan.org/t/g-compile-error-with-r-package/10628/5 "2019-09-09T16:07:47Z")

</div>

Thank you for your help! Actually I found ~/.R/Makevars.win file. I add a space before the g and the error message become

g++.exe: error: g: No such file or directory.

Do you know what happen here?

---

<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:** [September 9, 2019, 4:20pm UTC](https://discourse.mc-stan.org/t/g-compile-error-with-r-package/10628/6 "2019-09-09T16:20:18Z")

</div>

If you are going to have a ~/.R/Makevars.win file, it should be generated by

> **[stan-dev/rstan](https://github.com/stan-dev/rstan/wiki/Installing-RStan-from-source-on-Windows#configuration)**
>
> RStan, the R interface to Stan. Contribute to stan-dev/rstan development by creating an account on GitHub.

  
but I would just delete it.

---

<div class="post-metadata">

**Author:** ![decision-sciences](https://avatars.discourse-cdn.com/v4/letter/d/91b2a8/32.png) [@decision-sciences](https://discourse.mc-stan.org/u/decision-sciences)\
**Post date:** [September 10, 2019, 3:10pm UTC](https://discourse.mc-stan.org/t/g-compile-error-with-r-package/10628/7 "2019-09-10T15:10:28Z")

</div>

Thanks again for your help! Really appreciate it.

I did what this page told me to do and got the following error message when I run “install.packages(“rstan”, type = “source”)”

g++ -m32 -std=c++1y -I"C:/PROGRA~1/R/R-36~1.1/include" -DNDEBUG -I"…/inst/include" -I"." -I"C:/Users/natha/Documents/R/win-library/3.6/StanHeaders/include/src" -DBOOST\_DISABLE\_ASSERTS -DBOOST\_PHOENIX\_NO\_VARIADIC\_EXPRESSION -I"C:/Users/natha/Documents/R/win-library/3.6/Rcpp/include" -I"C:/Users/natha/Documents/R/win-library/3.6/RcppEigen/include" -I"C:/Users/natha/Documents/R/win-library/3.6/BH/include" -I"C:/Users/natha/Documents/R/win-library/3.6/StanHeaders/include" -O3 -march=native -c sparse\_extractors.cpp -o sparse\_extractors.o  
sh: g++: command not found

make: \*\*\* [C:/PROGRA~1/R/R-36~1.1/etc/i386/Makeconf:215: sparse\_extractors.o] Error 127  
ERROR: compilation failed for package ‘rstan’

- removing ‘C:/Users/natha/Documents/R/win-library/3.6/rstan’  
Warning in install.packages :

It seems I still have problems in g++

---

<div class="post-metadata">

**Author:** ![decision-sciences](https://avatars.discourse-cdn.com/v4/letter/d/91b2a8/32.png) [@decision-sciences](https://discourse.mc-stan.org/u/decision-sciences)\
**Post date:** [September 10, 2019, 3:13pm UTC](https://discourse.mc-stan.org/t/g-compile-error-with-r-package/10628/8 "2019-09-10T15:13:48Z")

</div>

When I deleted the ~/.R/Makevars.win file and installed the RStan package again, I got the following error message

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

- removing ‘C:/Users/natha/Documents/R/win-library/3.6/rstan’  
Warning in install.packages :  
installation of package ‘rstan’ had non-zero exit status

---

<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:** [September 10, 2019, 4:46pm UTC](https://discourse.mc-stan.org/t/g-compile-error-with-r-package/10628/9 "2019-09-10T16:46:12Z")

</div>

You might try

```
pkgbuild::with_build_tools(install.packages("rstan", type = "source"))

```

with that Makevars.win file.

---

<div class="post-metadata">

**Author:** ![decision-sciences](https://avatars.discourse-cdn.com/v4/letter/d/91b2a8/32.png) [@decision-sciences](https://discourse.mc-stan.org/u/decision-sciences)\
**Post date:** [September 11, 2019, 4:16pm UTC](https://discourse.mc-stan.org/t/g-compile-error-with-r-package/10628/10 "2019-09-11T16:16:18Z")

</div>

The error message is as following:

g++ -m32 -std=c++1y -I"C:/PROGRA~1/R/R-36~1.1/include" -DNDEBUG -I"…/inst/include" -I"." -I"C:/Users/natha/Documents/R/win-library/3.6/StanHeaders/include/src" -DBOOST\_DISABLE\_ASSERTS -DBOOST\_PHOENIX\_NO\_VARIADIC\_EXPRESSION -I"C:/Users/natha/Documents/R/win-library/3.6/Rcpp/include" -I"C:/Users/natha/Documents/R/win-library/3.6/RcppEigen/include" -I"C:/Users/natha/Documents/R/win-library/3.6/BH/include" -I"C:/Users/natha/Documents/R/win-library/3.6/StanHeaders/include" -march=native -O3 -march=native -c sparse\_extractors.cpp -o sparse\_extractors.o  
sh: g++: command not found

make: \*\*\* [C:/PROGRA~1/R/R-36~1.1/etc/i386/Makeconf:215: sparse\_extractors.o] Error 127  
ERROR: compilation failed for package ‘rstan’

- removing ‘C:/Users/natha/Documents/R/win-library/3.6/rstan’  
Warning in install.packages :  
installation of package ‘rstan’ had non-zero exit status

The downloaded source packages are in  
‘C:\Users\natha\AppData\Local\Temp\Rtmpw1Z9K5\downloaded\_packages’

---

<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:** [September 11, 2019, 4:45pm UTC](https://discourse.mc-stan.org/t/g-compile-error-with-r-package/10628/11 "2019-09-11T16:45:18Z")

</div>

OK, you may need to put a full path to wherever `g++` is, which is something like `C:/Rtools/mingw_64/bin/g++`.

---

<div class="post-metadata">

**Author:** ![decision-sciences](https://avatars.discourse-cdn.com/v4/letter/d/91b2a8/32.png) [@decision-sciences](https://discourse.mc-stan.org/u/decision-sciences)\
**Post date:** [September 12, 2019, 7:40pm UTC](https://discourse.mc-stan.org/t/g-compile-error-with-r-package/10628/12 "2019-09-12T19:40:57Z")

</div>

Thank you so much for your help!! Would you like to be more specific that where should I put this line on? I am so sorry about my limit knowledge in CS.

---

<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:** [September 12, 2019, 7:41pm UTC](https://discourse.mc-stan.org/t/g-compile-error-with-r-package/10628/13 "2019-09-12T19:41:51Z")

</div>

Put it in the ~/.R/Makefiles.win file like

```
CXX14 = C:/Rtools/mingw_64/bin/g++

```

---

<div class="post-metadata">

**Author:** ![decision-sciences](https://avatars.discourse-cdn.com/v4/letter/d/91b2a8/32.png) [@decision-sciences](https://discourse.mc-stan.org/u/decision-sciences)\
**Post date:** [September 12, 2019, 8:14pm UTC](https://discourse.mc-stan.org/t/g-compile-error-with-r-package/10628/14 "2019-09-12T20:14:18Z")

</div>

The error message dose not change.

---

<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:** [September 12, 2019, 10:40pm UTC](https://discourse.mc-stan.org/t/g-compile-error-with-r-package/10628/15 "2019-09-12T22:40:51Z")

</div>

Where is Rtools installed?

---

<div class="post-metadata">

**Author:** ![decision-sciences](https://avatars.discourse-cdn.com/v4/letter/d/91b2a8/32.png) [@decision-sciences](https://discourse.mc-stan.org/u/decision-sciences)\
**Post date:** [September 16, 2019, 2:32pm UTC](https://discourse.mc-stan.org/t/g-compile-error-with-r-package/10628/16 "2019-09-16T14:32:18Z")

</div>

C:\Rtools

---

<div class="post-metadata">

**Author:** ![decision-sciences](https://avatars.discourse-cdn.com/v4/letter/d/91b2a8/32.png) [@decision-sciences](https://discourse.mc-stan.org/u/decision-sciences)\
**Post date:** [September 16, 2019, 2:53pm UTC](https://discourse.mc-stan.org/t/g-compile-error-with-r-package/10628/17 "2019-09-16T14:53:21Z")

</div>

The Rstan package works well. I test with my codes. But it has problem install the DEEPest package we built based on RStan. And this package works well in MAC.

---

<div class="post-metadata">

**Author:** ![decision-sciences](https://avatars.discourse-cdn.com/v4/letter/d/91b2a8/32.png) [@decision-sciences](https://discourse.mc-stan.org/u/decision-sciences)\
**Post date:** [September 16, 2019, 2:59pm UTC](https://discourse.mc-stan.org/t/g-compile-error-with-r-package/10628/18 "2019-09-16T14:59:54Z")

</div>

Besides I am able to install both RStan and RStanarm using “install.package” in RStudio. However I can’t use “devtools::install\_github” to install RStanarm and the error message is above. g++: command not found

---

<div class="post-metadata">

**Author:** ![Chanchal\_Saini](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/chanchal_saini/32/15350_2.png) [@Chanchal\_Saini](https://discourse.mc-stan.org/u/Chanchal_Saini)\
**Post date:** [November 10, 2022, 8:50am UTC](https://discourse.mc-stan.org/t/g-compile-error-with-r-package/10628/19 "2022-11-10T08:50:20Z")

</div>

i need to install partialAR package but it showing the following error

Installing package into ‘C:/Users/hemant/AppData/Local/R/win-library/4.2’  
(as ‘lib’ is unspecified)

- installing _source_ package ‘partialAR’ …  
\*\* using staged installation  
\*\* libs  
g++ -std=gnu++11 -I"C:/PROGRA~1/R/R-42~1.2/include" -DNDEBUG -I’C:/Users/hemant/AppData/Local/R/win-library/4.2/Rcpp/include’ -I"C:/RBuildTools/4.2/x86\_64-w64-mingw32.static.posix/include" -O2 -Wall -mfpmath=sse -msse2 -mstackrealign -c RcppExports.cpp -o RcppExports.o  
g++ -std=gnu++11 -I"C:/PROGRA~1/R/R-42~1.2/include" -DNDEBUG -I’C:/Users/hemant/AppData/Local/R/win-library/4.2/Rcpp/include’ -I"C:/RBuildTools/4.2/x86\_64-w64-mingw32.static.posix/include" -O2 -Wall -mfpmath=sse -msse2 -mstackrealign -c cfit.cc -o cfit.o  
cfit.cc: In function ‘double loglik\_par\_c(Rcpp::NumericVector, double, double, double, double, double)’:  
cfit.cc:171:41: error: ‘PI’ was not declared in this scope  
171 | double nll = (n/2.0)_log(tvar \* 2.0_PI) + esumsq/(2.0\*tvar);  
| ^~  
cfit.cc: In function ‘double loglik\_par\_t\_c(Rcpp::NumericVector, double, double, double, double, double, double)’:  
cfit.cc:202:66: error: ‘PI’ was not declared in this scope  
202 | double const\_term = n \* (lgamma((nu+1.0)_0.5) - 0.5_log(nu \* PI) -  
| ^~  
make: \*\*\* [C:/PROGRA~1/R/R-42~1.2/etc/x64/Makeconf:258: cfit.o] Error 1  
ERROR: compilation failed for package ‘partialAR’
- removing ‘C:/Users/hemant/AppData/Local/R/win-library/4.2/partialAR’  
Warning message:  
In i.p(…) :  
installation of package ‘C:/Users/hemant/AppData/Local/Temp/RtmpKG8NNY/file20cc1b6a198f/partialAR\_1.0.12.tar.gz’ had non-zero exit status

please tell how can i resolved it

---

<div class="post-metadata">

**Author:** ![andrjohns](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/andrjohns/32/15297_2.png) [@andrjohns](https://discourse.mc-stan.org/u/andrjohns)\
**Post date:** [November 10, 2022, 9:17am UTC](https://discourse.mc-stan.org/t/g-compile-error-with-r-package/10628/20 "2022-11-10T09:17:52Z")

</div>

Please don’t post multiple topics/messages for the same issue
