Compilation ERROR - brms and stan model

  • Operating System: Microsoft Windows [Version 10.0.17134.345]
  • brms Version: 2.5.0

I have been using rstan and brms but today they stopped working unexpectedly.

I have tried uninstalling and reinstalling following the instructions from here Home · stan-dev/rstan Wiki · GitHub and I am able to get 10 when I do

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

Still, when I run the code:

DT<-structure(list(c = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L), .Label = c("a", "b"), class = "factor"), 
x = c(2004L, 2005L, 2006L, 2007L, 2008L, 2010L, 2012L, 2010L, 
2012L, 2010L, 2005L, 2007L, 2012L, 2005L), y = c(11.05826397, 
15.56776557, 49.50980392, 64.53900709, 75, 68.18181818, 99.86357435, 
100, 99.26739927, 98.52941176, 100, 95.94594595, 99.64157706, 
100)), class = "data.frame", row.names = c(NA, -14L))
library(brms)
fit <- brm(y~ x, data = DT)

I get the error:

Compiling the C++ model
Error in compileCode(f, code, language = language, verbose = verbose) :
Compilation ERROR, function(s)/method(s) not created! In file included from C:/Users/…/Documents/R/win-library/3.5/BH/include/boost/config.hpp:39:0,
from C:/Users/…/Documents/R/win-library/3.5/BH/include/boost/math/tools/config.hpp:13,
from C:/Users/…/Documents/R/win-library/3.5/StanHeaders/include/stan/math/rev/core/var.hpp:7,
from C:/Users/…/Documents/R/win-library/3.5/StanHeaders/include/stan/math/rev/core/gevv_vvv_vari.hpp:5,
from C:/Users/…/Documents/R/win-library/3.5/StanHeaders/include/stan/math/rev/core.hpp:12,
from C:/Users/…/Documents/R/win-library/3.5/StanHeaders/include/stan/math/rev/mat.hpp:4,
from C:/Users/…/Documents/R/win-library/3.5/StanHeaders/include/stan/math.hpp:4,
from C:/Users/…/Documents/R/win-library/3.5/StanHeaders/include/src/stan
In addition: Warning messages:
1: In rstan::stan_model(model_code = x$model, save_dso = save_dso) :
StanHeaders version is ahead of rstan version; update to latest rstan
2: In system(cmd, intern = !verbose) :
running command ‘C:/PROGRA~1/R/R-3.5.1/bin/x64/R CMD SHLIB file110c1cb656fa.cpp 2> file110c1cb656fa.cpp.err.txt’ had status 1

I get the same error when I run stan model from here:

I have reinstalled Rtools several times and even uninstalled and reinstalled R and R Studio, without success.

Any help would be much appreciated.

Thanks @bgoodri

Could you kindly clarify how exactly I do this on windows 10 64?

'Also, you need to define CXX14 and CXX14FLAGS in your ~/.R/Makevars file. This should be automatic on a Mac if you use the installer. It probably has to be done manually on WIndows, in which case ~/.R/Makevars should read as

CXX14 = g++
CXX14FLAGS = -O3 -Wno-unused-variable -Wno-unused-function

‘’

Thank you very much for your help

1 Like

Just use a text editor to open the file given by whatever

normalizePath("~/.R/Makevars")

evaluates to and write in those two lines.

Hi @bgoodri,

Here is the text that is in my Makevars file:

CXXFLAGS=-O3 -Wno-unused-variable -Wno-unused-function

CXXFLAGS=-O3 -Wno-unused-variable -Wno-unused-function

CXXFLAGS=-O3 -Wno-unused-variable -Wno-unused-function

CXXFLAGS=-O3 -Wno-unused-variable -Wno-unused-function

CXX14FLAGS=-O3 -Wno-unused-variable -Wno-unused-function
CXX14 = g++

CXX14FLAGS=-O3 -Wno-unused-variable -Wno-unused-function
CXX14 = g++

CXX14FLAGS=-O3 -Wno-unused-variable -Wno-unused-function
CXX14 = g++

CXX14FLAGS=-O3 -Wno-unused-variable -Wno-unused-function
CXX14 = g++

It seems that it is already with the:

CXX14 = g++
CXX14FLAGS = -O3 -Wno-unused-variable -Wno-unused-function

Any other change should I make?

Thanks in advance

Is there more to the error message?

And did you also first do the Sys.setenv(USE_CXX14 = 1) thing?

The error is:

Compiling the C++ model Error in compileCode(f, code, language = language, verbose = verbose) : Compilation ERROR, function(s)/method(s) not created! In file included from C:/Users/.../Documents/R/win-library/3.5/BH/include/boost/config.hpp:39:0, from C:/Users/.../Documents/R/win-library/3.5/BH/include/boost/math/tools/config.hpp:13, from C:/Users/.../Documents/R/win-library/3.5/StanHeaders/include/stan/math/rev/core/var.hpp:7, from C:/Users/.../Documents/R/win-library/3.5/StanHeaders/include/stan/math/rev/core/gevv_vvv_vari.hpp:5, from C:/Users/.../Documents/R/win-library/3.5/StanHeaders/include/stan/math/rev/core.hpp:12, from C:/Users/.../Documents/R/win-library/3.5/StanHeaders/include/stan/math/rev/mat.hpp:4, from C:/Users/.../Documents/R/win-library/3.5/StanHeaders/include/stan/math.hpp:4, from C:/Users/.../Documents/R/win-library/3.5/StanHeaders/include/src/stan In addition: Warning messages: 1: In rstan::stan_model(model_code = x$model, save_dso = save_dso) : StanHeaders version is ahead of rstan version; update to latest rstan 2: In system(cmd, intern = !verbose) : running command 'C:/PROGRA~1/R/R-3.5.1/bin/x64/R CMD SHLIB file110c1cb656fa.cpp 2> file110c1cb656fa.cpp.err.txt' had status 1

Also, I tried replacing everything in the Makevars file by

CXX14 = g++
CXX14FLAGS = -O3 -Wno-unused-variable -Wno-unused-function

and running

Sys.setenv(USE_CXX14 = 1)

before the session, but the error continues.

Thanks in advance

Try putting

CXX14 = g++ -std=c++1y

into the ~/.R/Makevars file instead of

CXX14 = g++

Just replaced and it works now.

Thanks a lot, @bgoodri.

You saved me.

I have no words to express my gratitude.

Suffering the same error (here on my very first day of trying Stan out), and the solutions suggested above haven’t helped so far, the error persists. Do you think installing prior versions of the r packages might work?

EDIT: it did work!

Hello all. I’m trying to get my rstan install to work and I had the same issues as this thread however when I made the “-std=c++1y” change to Makevars, my error changed to the following:

Error in compileCode(f, code, language = language, verbose = verbose) :
Compilation ERROR, function(s)/method(s) not created! C:/Program Files/R/R-3.5.1/library/StanHeaders/libs/x64/StanHeaders.dll: file not recognized: File format not recognized
collect2.exe: error: ld returned 1 exit status
In addition: Warning message:
In stan_model(MODELS, model_name = model) :
StanHeaders version is ahead of rstan version; update to latest rstan

Thanks in advance for any help,

Best,

–a

I think it means that you need to reinstall StanHeaders.

Thanks for your help.

I just tried it but got the same error.

The warning is right about the relative versions, I have 2.18.0 StanHeaders and 2.17.4 rstan. Should I try to find an older version of the StanHeaders package?

ciao,

–a

That is an option, but let’s see if we can figure out what the problem is. Are you multiarching? Maybe change that line in your ~/.R/Makevars to

CXX14 = g++ -m$(WIN) -std=c++1y

Not mutli-arching. This changed the error to:

Error in compileCode(f, code, language = language, verbose = verbose) :
Compilation ERROR, function(s)/method(s) not created! file26fc582141a5.cpp:1:0: sorry, unimplemented: 64-bit mode not compiled in

^
make: *** [C:/PROGRA~1/R/R-35~1.1/etc/x64/Makeconf:215: file26fc582141a5.o] Error 1
In addition: Warning messages:
1: In stan_model(file, model_name = model_name, model_code = model_code, :
StanHeaders version is ahead of rstan version; update to latest rstan
2: In system(cmd, intern = !verbose) :
running command ‘C:/PROGRA~1/R/R-35~1.1/bin/x64/R CMD SHLIB file26fc582141a5.cpp 2> file26fc582141a5.cpp.err.txt’ had status 1

So, do you have a 32bit R on a 64bit OS or something? What is the output of R.version?

platform x86_64-w64-mingw32
arch x86_64
os mingw32
system x86_64, mingw32
status
major 3
minor 5.1
year 2018
month 07
day 02
svn rev 74947
language R
version.string R version 3.5.1 (2018-07-02)
nickname Feather Spray

And what is the output of system("g++ --version")?

G__~1.EXE (i686-posix-dwarf, Built by MinGW-W64 project) 4.9.3
Copyright © 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.