Compilation ERROR - brms and stan model

C:\Program Files\R\R-3.5.1\bin\x64
C:\Rtools\bin
C:\Rtools\mingw_32\bin
C:\Rtools\mingw_64\bin
C:\Windows\system32
C:\Windows
C:\Windows\System32\Wbem
C:\Windows\System32\WindowsPowerShell\v1.0
C:\Program Files\MiKTeX 2.9\miktex\bin\x64
C:\Program Files (x86)\Sennheiser\SoftphoneSDK\

OK, according to @paul.buerkner , the problem is the presence of C:\Rtools\mingw_32\bin in your PATH. To delete this, click something like

  1. left-click on Start
  2. right-click on Computer
  3. left-click on Properties
  4. left-click on Advanced System Settings
  5. left-click on Environmental variables
  6. scroll down in the bottom window to Path and left-click it
  7. left-click Edit
  8. move the cursor all the way to the left then delete the part that says C:\Rtools\mingw_32\bin; (be sure to delete exactly one semi-colon)
  9. left-click three Ok buttons

For me, it looks like

Then restart R, and try

fx <- inline::cxxfunction( signature(x = "integer", y = "numeric" ) , '
	return ScalarReal( INTEGER(x)[0] * REAL(y)[0] ) ;
' )
fx( 2L, 5 ) # should be 10

without and then with first specifying Sys.setenv(USE_CXX14 = 1). Then rstan should work.

I am unfortunately getting a similar error here now. This happened suddenly - brms was working one day, and now it does not. Here is the error I receive.

> bprior1 <- prior(student_t(5,0,10), class = b) + 
  • prior(cauchy(0,2), class = sd)

fit1 ← brm(count ~ log_Age_c + log_Base4_c * Trt + (1|patient),

  •         data = epilepsy, family = poisson(), prior = bprior1)
    

Compiling the C++ model
Error in compileCode(f, code, language = language, verbose = verbose) :
Compilation ERROR, function(s)/method(s) not created! Error in .shlib_internal(commandArgs(TRUE)) :
C++14 standard requested but CXX14 is not defined
Calls: → .shlib_internal
Execution halted
In addition: Warning message:
In system(cmd, intern = !verbose) :
running command ‘C:/PROGRA~1/R/R-35~1.1/bin/x64/R CMD SHLIB file28b039dd1f8f.cpp 2> file28b039dd1f8f.cpp.err.txt’ had status 1

I have tried many of the suggestions here. I’ll just report a few of the results.

fx <- inline::cxxfunction( signature(x = "integer", y = "numeric" ) , '
return ScalarReal( INTEGER(x)[0] * REAL(y)[0] ) ;
                       ' )
fx( 2L, 5 ) # should be 10

Returns 10.

So, based on the last comment I have tried playing with the system path a bit, and this is what it looks like…

 > cat(strsplit(Sys.getenv("PATH"), ";")[[1]], sep = "\n")

C:\Program Files\R\R-3.5.1\bin\x64
C:\Program Files\R\R-3.5.1\bin\x64
C:\Rtools\bin
C:\Rtools\mingw_64\bin
C:\Program Files\ImageMagick-6.9.2-Q16
C:\ProgramData\Oracle\Java\javapath
C:\Program Files (x86)\Intel\iCLS Client
C:\Program Files\Intel\iCLS Client
C:\windows\system32
C:\windows
C:\windows\System32\Wbem
C:\windows\System32\WindowsPowerShell\v1.0
C:\ProgramData\Lenovo\ReadyApps
C:\Program Files (x86)\Lenovo\Password Manager
C:\Program Files\MiKTeX 2.9\miktex\bin\x64
C:\WINDOWS\system32
C:\WINDOWS
C:\WINDOWS\System32\Wbem
C:\WINDOWS\System32\WindowsPowerShell\v1.0
C:\Program Files\Intel\Intel(R) Management Engine Components\DAL
C:\Program Files\Intel\Intel(R) Management Engine Components\IPT
C:\Program Files\IBM\SPSS\Statistics\24\JRE\bin
C:\Program Files\Microsoft SQL Server\120\Tools\Binn
C:\WINDOWS\System32\OpenSSH
C:\Users\Jason\AppData\Local\Microsoft\WindowsApps

I’ll also note that I do not seem to have a ~/.R/Makevars file.

> normalizePath("~/.R/Makevars")

[1] “C:\Users\Jason\Documents\.R\Makevars”
Warning message:
In normalizePath(path.expand(path), winslash, mustWork) :
path[1]=“C:/Users/Jason/Documents/.R/Makevars”: The system cannot find the path specified

When I search for one, I have two that are associated with the Rcpp and RcppArmadillo packages. Needless to say, I am fairly lost here. Any advice would be welcome.

Thanks - I focused my search there and found script to create a makevars file. That solved my problem. For any other laypersons out there who run into this same issue, the following resolved it for me.

dotR <- file.path(Sys.getenv("HOME"), ".R")
if (!file.exists(dotR)) 
  dir.create(dotR)
M <- file.path(dotR, "Makevars")
if (!file.exists(M)) 
  file.create(M)
cat("\nCXX14FLAGS=-O3 -Wno-unused-variable -Wno-unused-function",
    "CXX14 = $(BINPREF)g++ -m$(WIN) -std=c++1y",
    "CXX11FLAGS=-O3 -Wno-unused-variable -Wno-unused-function",
    file = M, sep = "\n", append = TRUE)

https://github.com/stan-dev/rstan/wiki/Installing-RStan-on-Windows

1 Like

Those instructions are also applicable if you are the Pope.

5 Likes

I have amended the path per instructions. I get the fx function to return 10 both with and without setting USE_CXX14. When I load rstan and try to run 8schools, I get the following:

Restarting R session…

fx ← inline::cxxfunction( signature(x = “integer”, y = “numeric” ) , ’

  •         return ScalarReal( INTEGER(x)[0] * REAL(y)[0] ) ;
    
  • ’ )

fx( 2L, 5 ) # should be 10
[1] 10
Sys.setenv(USE_CXX14=1)
fx ← inline::cxxfunction( signature(x = “integer”, y = “numeric” ) , ’

  •         return ScalarReal( INTEGER(x)[0] * REAL(y)[0] ) ;
    
  • ’ )

fx( 2L, 5 ) # should be 10
[1] 10

library(rstan)
Loading required package: ggplot2
Loading required package: StanHeaders
rstan (Version 2.18.1, GitRev: 2e1f913d3ca3)
For execution on a local, multicore CPU with excess RAM we recommend calling
options(mc.cores = parallel::detectCores()).
To avoid recompilation of unchanged Stan programs, we recommend calling
rstan_options(auto_write = TRUE)
schools_dat ← list(J = 8,

  •                 y = c(28,  8, -3,  7, -1,  1, 18, 12),
    
  •                 sigma = c(15, 10, 16, 11,  9, 11, 10, 18))
    

fit ← stan(file = ‘./code/8schools.stan’, data = schools_dat,

  •         iter = 1000, chains = 4)
    

Error in if (grepl(pattern, makefile_txt[i])) { :
argument is of length zero

Here is the path for reference:
C:\Program Files\R\R-3.5.1\bin\x64
C:\Rtools\bin
C:\Rtools\mingw_64\bin
C:\Windows\System32
C:\Windows
C:\Windows\System32\wbem
C:\Windows\System32\WindowsPowerShell\v1.0
C:\Program Files\MiKTeX 2.9\miktex\bin\x64
C:\Program Files (x86)\Sennheiser\SoftphoneSDK\

You seem to have the same problem as

which I currently do not understand fully. Can you go through the posts on that thread and how much of it applies to your situation?

That’s my situation too.

Right. What does system2(file.path(Sys.getenv("R_HOME"), "bin", "R"), args = "CMD SHLIB --dry-run", stdout = TRUE) say?

[1] “’\\sffile01\Projects2\5838_EV_Acceleration\Analysis\Statistical Models’”
[2] “CMD.EXE was started with the above path as the current directory.”
[3] “UNC paths are not supported. Defaulting to Windows directory.”
[4] “make cmd is”
[5] " make -f “C:/PROGRA~1/R/R-35~1.1/etc/x64/Makeconf” -f “C:/PROGRA~1/R/R-35~1.1/share/make/winshlib.mk” -f “C:/Users/armando levy/Documents/.R/Makevars” SHLIB="" WIN=64 TCLBIN=64 OBJECTS="""
[6] “”
[7] “make would use”
[8] “make: Nothing to be done for ‘all’.”

It looks like I am going to have to generalize the function in rstan that deals with this because I did not take into account the possibility of this “UNC paths are not supported” business. It might be a few days. In the meantime, you can use Stan via https://rstudio.cloud/project/56157 .

Can you try installing rstan from GitHub to see if it gets past that error:

devtools::install_github("stan-dev/rstan", ref = "develop", subdir = "rstan/rstan")

devtools::install_github(“stan-dev/rstan”, ref = “develop”, subdir = “rstan/rstan”)
Downloading GitHub repo stan-dev/rstan@develop
/Rtools/bin/tar: stan-dev-rstan-d96845d/StanHeaders/inst/include/libsundials: Cannot create symlink to ‘mathlib/lib/sundials_3.1.0/’: No such file or directory
/Rtools/bin/tar: stan-dev-rstan-d96845d/StanHeaders/inst/include/src: Cannot create symlink to ‘upstream/src/’: No such file or directory
/Rtools/bin/tar: stan-dev-rstan-d96845d/StanHeaders/inst/include/stan: Cannot create symlink to ‘mathlib/stan/’: No such file or directory
/Rtools/bin/tar: Exiting with failure status due to previous errors
External tar failed with --force-local, trying without
/Rtools/bin/tar: stan-dev-rstan-d96845d/StanHeaders/inst/include/libsundials: Cannot create symlink to ‘mathlib/lib/sundials_3.1.0/’: No such file or directory
/Rtools/bin/tar: stan-dev-rstan-d96845d/StanHeaders/inst/include/src: Cannot create symlink to ‘upstream/src/’: No such file or directory
/Rtools/bin/tar: stan-dev-rstan-d96845d/StanHeaders/inst/include/stan: Cannot create symlink to ‘mathlib/stan/’: No such file or directory
/Rtools/bin/tar: Exiting with failure status due to previous errors
These packages have more recent versions available.
Which would you like to update?

1: rlang (0.2.2 → 0.3.0) [CRAN]

Enter one or more numbers separated by spaces, or an empty line to cancel
1:
√ checking for file ‘C:\Users\armando levy\AppData\Local\Temp\RtmpGgVORU\remotes26c06a222286\stan-dev-rstan-d96845d\rstan\rstan/DESCRIPTION’ …

  • preparing ‘rstan’: (2s)
    √ checking DESCRIPTION meta-information …
  • cleaning src
  • checking for LF line-endings in source and make files and shell scripts (746ms)
  • checking for empty or unneeded directories
  • looking to see if a ‘data/datalist’ file should be added
  • building ‘rstan_2.18.2.tar.gz’

‘\sffile01\Projects2\5838_EV_Acceleration\Analysis\Statistical Models\code’
CMD.EXE was started with the above path as the current directory.
UNC paths are not supported. Defaulting to Windows directory.

  • installing source package ‘rstan’ …
    ** libs

*** arch - i386
g++ -m32 -std=c++1y -I"C:/PROGRA~1/R/R-35~1.1/include" -DNDEBUG -I"…/inst/include" -I""C:/PROGRA~1/R/R-35~1.1/bin/i386/Rscript" --vanilla -e "cat(system.file('include', 'src', package = 'StanHeaders'))"" -DBOOST_DISABLE_ASSERTS -DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION -I"C:/Program Files/R/R-3.5.1/library/Rcpp/include" -I"C:/Program Files/R/R-3.5.1/library/RcppEigen/include" -I"C:/Program Files/R/R-3.5.1/library/BH/include" -I"C:/Program Files/R/R-3.5.1/library/StanHeaders/include" -O3 -Wno-unused-variable -Wno-unused-function -c chains.cpp -o chains.o
In file included from C:/Rtools/mingw_64/x86_64-w64-mingw32/include/c++/random:49:0,
from C:/Rtools/mingw_64/x86_64-w64-mingw32/include/c++/bits/stl_algo.h:66,
from C:/Rtools/mingw_64/x86_64-w64-mingw32/include/c++/algorithm:62,
from C:/Program Files/R/R-3.5.1/library/RcppEigen/include/Eigen/Core:285,
from C:/Program Files/R/R-3.5.1/library/RcppEigen/include/Eigen/Dense:1,
from C:/Program Files/R/R-3.5.1/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:4,
from C:/Program Files/R/R-3.5.1/library/StanHeaders/include/stan/math/prim/mat/fun/mean.hpp:5,
from chains.cpp:19:
C:/Rtools/mingw_64/x86_64-w64-mingw32/include/c++/bits/random.h:106:26: error: expected unqualified-id before ‘__int128’
{ typedef unsigned __int128 type; };
^
make: *** [C:/PROGRA~1/R/R-35~1.1/etc/i386/Makeconf:215: chains.o] Error 1
ERROR: compilation failed for package ‘rstan’

  • removing ‘C:/Program Files/R/R-3.5.1/library/rstan’
  • restoring previous ‘C:/Program Files/R/R-3.5.1/library/rstan’
    In R CMD INSTALL
    Error in i.p(…) :
    (converted from warning) installation of package ‘C:/Users/ARMAND~1/AppData/Local/Temp/RtmpGgVORU/file26c0bb3383d/rstan_2.18.2.tar.gz’ had non-zero exit status
    In addition: Warning message:
    In utils::untar(tarfile, …) :
    ‘tar.exe -zxf “C:\Users\ARMAND~1\AppData\Local\Temp\RtmpGgVORU\file26c034342d2f.tar.gz” -C “C:/Users/ARMAND~1/AppData/Local/Temp/RtmpGgVORU/remotes26c06a222286”’ returned error code 2

OK. First, you should install the StanHeaders binary via

install.packages("StanHeaders")

before trying

devtools::install_github("stan-dev/rstan", ref = "develop", subdir = "rstan/rstan")

but the error that says

C:/Rtools/mingw_64/x86_64-w64-mingw32/include/c++/bits/random.h:106:26: error: expected unqualified-id before ‘__int128’

indicates that your toolchain is not configured correctly. Since Rtools is in C:/Rtools, you should not need a ~/.Rprofile file that sets the BINPREF environment variable but your ~/.R/Makevars file should look exactly like what is produced by

dotR <- file.path(Sys.getenv("HOME"), ".R")
if (!file.exists(dotR)) 
  dir.create(dotR)
M <- file.path(dotR, "Makevars.win")
if (!file.exists(M)) 
  file.create(M)
cat("\nCXX14FLAGS=-O3 -Wno-unused-variable -Wno-unused-function",
    "CXX14 = $(BINPREF)g++ -m$(WIN) -std=c++1y",
    "CXX11FLAGS=-O3 -Wno-unused-variable -Wno-unused-function",
    file = M, sep = "\n", append = TRUE)

Also, make sure your PATH does not include any directories that have mingw_32 or mingw_64 in them when you install Rtools35.

OK, configured Makevars as above, cleaned up the system Path in Windows and reinstalled Rtools. When I did that C:\Rtools\mingw_64\bin got added to the Path:

cat(strsplit(Sys.getenv(“PATH”), “;”)[[1]], sep = “\n”)
C:\Program Files\R\R-3.5.1\bin\x64
C:\Rtools\bin
C:\Rtools\mingw_64\bin
C:\Windows\system32
C:\Windows
C:\Windows\System32\Wbem
C:\Windows\System32\WindowsPowerShell\v1.0
C:\Program Files\MiKTeX 2.9\miktex\bin\x64
C:\Program Files (x86)\Sennheiser\SoftphoneSDK\

When I look up Path in Windows the “mingw_64” is not there.

Edit: I should add that the mingw_64 was not in the Path window during the Rtools install.

–a

And you still get the same error when you try to install rstan from GitHub?

Here’s the output below.

devtools::install_github(“stan-dev/rstan”, ref = “develop”, subdir = “rstan/rstan”)
Downloading GitHub repo stan-dev/rstan@develop
/Rtools/bin/tar: stan-dev-rstan-d96845d/StanHeaders/inst/include/libsundials: Cannot create symlink to ‘mathlib/lib/sundials_3.1.0/’: No such file or directory
/Rtools/bin/tar: stan-dev-rstan-d96845d/StanHeaders/inst/include/src: Cannot create symlink to ‘upstream/src/’: No such file or directory
/Rtools/bin/tar: stan-dev-rstan-d96845d/StanHeaders/inst/include/stan: Cannot create symlink to ‘mathlib/stan/’: No such file or directory
/Rtools/bin/tar: Exiting with failure status due to previous errors
External tar failed with --force-local, trying without
/Rtools/bin/tar: stan-dev-rstan-d96845d/StanHeaders/inst/include/libsundials: Cannot create symlink to ‘mathlib/lib/sundials_3.1.0/’: No such file or directory
/Rtools/bin/tar: stan-dev-rstan-d96845d/StanHeaders/inst/include/src: Cannot create symlink to ‘upstream/src/’: No such file or directory
/Rtools/bin/tar: stan-dev-rstan-d96845d/StanHeaders/inst/include/stan: Cannot create symlink to ‘mathlib/stan/’: No such file or directory
/Rtools/bin/tar: Exiting with failure status due to previous errors
These packages have more recent versions available.
Which would you like to update?

1: rlang (0.2.2 → 0.3.0) [CRAN]

Enter one or more numbers separated by spaces, or an empty line to cancel
1:
√ checking for file ‘C:\Users\armando levy\AppData\Local\Temp\RtmpqQEarM\remotes104449fe556c\stan-dev-rstan-d96845d\rstan\rstan/DESCRIPTION’ …

  • preparing ‘rstan’: (1.8s)
    √ checking DESCRIPTION meta-information …
  • cleaning src
  • checking for LF line-endings in source and make files and shell scripts (725ms)
  • checking for empty or unneeded directories
  • looking to see if a ‘data/datalist’ file should be added
  • building ‘rstan_2.18.2.tar.gz’

‘\sffile01\Projects2\5838_EV_Acceleration\Analysis\Statistical Models\code’
CMD.EXE was started with the above path as the current directory.
UNC paths are not supported. Defaulting to Windows directory.

  • installing source package ‘rstan’ …
    ** libs

*** arch - i386
C:/Rtools/mingw_64/bin/g++ -m32 -std=c++1y -I"C:/PROGRA~1/R/R-35~1.1/include" -DNDEBUG -I"…/inst/include" -I""C:/PROGRA~1/R/R-35~1.1/bin/i386/Rscript" --vanilla -e "cat(system.file('include', 'src', package = 'StanHeaders'))"" -DBOOST_DISABLE_ASSERTS -DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION -I"C:/Program Files/R/R-3.5.1/library/Rcpp/include" -I"C:/Program Files/R/R-3.5.1/library/RcppEigen/include" -I"C:/Program Files/R/R-3.5.1/library/BH/include" -I"C:/Program Files/R/R-3.5.1/library/StanHeaders/include" -O3 -Wno-unused-variable -Wno-unused-function -c chains.cpp -o chains.o
In file included from C:/Rtools/mingw_64/x86_64-w64-mingw32/include/c++/random:49:0,
from C:/Rtools/mingw_64/x86_64-w64-mingw32/include/c++/bits/stl_algo.h:66,
from C:/Rtools/mingw_64/x86_64-w64-mingw32/include/c++/algorithm:62,
from C:/Program Files/R/R-3.5.1/library/RcppEigen/include/Eigen/Core:285,
from C:/Program Files/R/R-3.5.1/library/RcppEigen/include/Eigen/Dense:1,
from C:/Program Files/R/R-3.5.1/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:4,
from C:/Program Files/R/R-3.5.1/library/StanHeaders/include/stan/math/prim/mat/fun/mean.hpp:5,
from chains.cpp:19:
C:/Rtools/mingw_64/x86_64-w64-mingw32/include/c++/bits/random.h:106:26: error: expected unqualified-id before ‘__int128’
{ typedef unsigned __int128 type; };
^
make: *** [C:/PROGRA~1/R/R-35~1.1/etc/i386/Makeconf:215: chains.o] Error 1
ERROR: compilation failed for package ‘rstan’

  • removing ‘C:/Program Files/R/R-3.5.1/library/rstan’
  • restoring previous ‘C:/Program Files/R/R-3.5.1/library/rstan’
    In R CMD INSTALL
    Error in i.p(…) :
    (converted from warning) installation of package ‘C:/Users/ARMAND~1/AppData/Local/Temp/RtmpqQEarM/file104433e81814/rstan_2.18.2.tar.gz’ had non-zero exit status
    In addition: Warning message:
    In utils::untar(tarfile, …) :
    ‘tar.exe -zxf “C:\Users\ARMAND~1\AppData\Local\Temp\RtmpqQEarM\file104478623cc9.tar.gz” -C “C:/Users/ARMAND~1/AppData/Local/Temp/RtmpqQEarM/remotes104449fe556c”’ returned error code 2

I was running into this error before, but it went away when I got the 3.5 toolchain setup right. But your setup looks like my setup now. What is your Sys.getenv("BINPREF")?

[1] “C:/Rtools/mingw_64/bin/”

Change to C:/Rtools/bin ?