Compilation ERROR - brms and stan model

Does

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

work?

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

^
make: *** [C:/PROGRA~1/R/R-35~1.1/etc/x64/Makeconf:215: file26fc58132767.o] Error 1
In addition: Warning message:
In system(cmd, intern = !verbose) :
running command ‘C:/PROGRA~1/R/R-35~1.1/bin/x64/R CMD SHLIB file26fc58132767.cpp 2> file26fc58132767.cpp.err.txt’ had status 1

fx( 2L, 5 ) # should be 10
Error in fx(2L, 5) : could not find function “fx”

Okay, this seems like a general configuration problem rather than specifically a Stan one, but what is the content of ~/.R/Makevars ?

CXX14FLAGS=-O3 -Wno-unused-variable -Wno-unused-function
CXX14 = g++ -m$(WIN) -std=c++1y

OK, delete all that temporarily, and try

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

again.

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

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

Error in .shlib_internal(commandArgs(TRUE)) :
C++14 standard requested but CXX14 is not defined
Calls: → .shlib_internal
Execution halted

ERROR(s) during compilation: source code errors or compiler configuration errors!

Program source:
1:
2: // includes from the plugin
3: #include <R.h>
4: #include <Rdefines.h>
5: #include <R_ext/Error.h>
6:
7:
8: // user includes
9:
10:
11: // declarations
12: extern “C” {
13: SEXP file26fcc5d3353( SEXP x, SEXP y) ;
14: }
15:
16: // definition
17:
18: SEXP file26fcc5d3353( SEXP x, SEXP y ){
19:
20: return ScalarReal( INTEGER(x)[0] * REAL(y)[0] ) ;
21:
22: Rf_warning(“your C++ program does not return anything”);
23: return R_NilValue ;
24: }
25:
26:
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 file26fcc5d3353.cpp 2> file26fcc5d3353.cpp.err.txt’ had status 1

Sorry, forgot to say in a clean R session and without doing Sys.setenv(USE_CXX=1).

Restarting R session…

library(rstan)
Loading required package: ggplot2
Loading required package: StanHeaders
rstan (Version 2.17.4, 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)

fx ← inline::cxxfunction( signature(x = “integer”, y = “numeric” ) , ’
Error: unexpected ‘>’ in “>”
+ return ScalarReal( INTEGER(x)[0] * REAL(y)[0] ) ;
Error: unexpected symbol in " + return ScalarReal"
+ ’ )

  • Error in .shlib_internal(commandArgs(TRUE)) :
  • C++14 standard requested but CXX14 is not defined
    
  • Calls: → .shlib_internal
  • Execution halted
  • ERROR(s) during compilation: source code errors or compiler configuration errors!
  • Program source:
    
  • 1: 
    
  • 2: // includes from the plugin
    
  • 3: #include <R.h>
  • 4: #include <Rdefines.h>
    
  • 5: #include <R_ext/Error.h>
    
  • 6: 
    
  • 7: 
    
  • 8: // user includes
    
  • 9:
  • 10: 
    
  • 11: // declarations
    
  • 12: extern “C” {
  • 13: SEXP file26fcc5d3353( SEXP x, SEXP y) ;
    
  • 14: }
    
  • 15:
  • 16: // definition
    
  • 17:
  • 18: SEXP file26fcc5d3353( SEXP x, SEXP y ){
    
  •     19: 
    
  •         20: 	return ScalarReal( INTEGER(x)[0] * REAL(y)[0] ) ;
    
  •     21:                             
    
  •         22: Rf_warning("your C++ program does not return anything"); 
    
  •     23:  return R_NilValue ; 
    
  •     24: }
    
  • 25:
  • 26: 
    
  • 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

Okay, sorry for the back and forth. Do a

Sys.unsetenv("USE_CXX14")

then a

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

Sys.setenv(USE_CXX14=1)
library(rstan)
Loading required package: ggplot2
Loading required package: StanHeaders
rstan (Version 2.17.4, 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)
fx ← inline::cxxfunction( signature(x = “integer”, y = “numeric” ) , ’

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

Error in .shlib_internal(commandArgs(TRUE)) :
C++14 standard requested but CXX14 is not defined
Calls: → .shlib_internal
Execution halted

Sys.unsetenv("USE_CXX14") rather than Sys.setenv(USE_CXX14 = 1).

I got locked out for 20 hours there but I meant to write:
That works. yes.

–a

An update:

Running R 3.5.1 (64bit)
I’ve updated rstan to 2.18.1
StahHeaders is 2.18.0

When I run: Sys.setenv(USE_CXX14=1)
Rtools breaks. If I run: Sys.unsetenv(“USE_CXX14”)
Rtools comes back, but when I try to run rstan code I get this:

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

The BINPREF environment is set to C:/Rtools/mingw_64/bin/

What do you mean by

If I start R then run

fx <- inline::cxxfunction( signature(x = “integer”, y = “numeric” ) , ’
return ScalarReal( INTEGER(x)[0] * REAL(y)[0] ) ;
’ )

fx( 2L, 5 ) # should be 10

It works. If I run
Sys.setenv(USE_CXX14=1)
and try again the fx definition won’t compile, I get:

Error in compileCode(f, code, language = language, verbose = verbose) :
Compilation ERROR, function(s)/method(s) not created! C:/PROGRA~1/R/R-35~1.1/bin/x64/R.dll: file not recognized: File format not recognized
collect2.exe: error: ld returned 1 exit status

I get a similar message when I try the 8 schools example after loading rstan.

Thanks,

–a

Did you build R from source? Also, what version of Rtools do you have? Maybe try with

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

in ~/.R/Makevars .

Did not build R from source.
I have gcc v. 4.9.3
I made the change to Makevars and the error changed on trying to compile the fx function:

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

^
make: *** [C:/PROGRA~1/R/R-35~1.1/etc/x64/Makeconf:215: file2860280d275.o] Error 1
In addition: Warning message:
In system(cmd, intern = !verbose) :
running command ‘C:/PROGRA~1/R/R-35~1.1/bin/x64/R CMD SHLIB file2860280d275.cpp 2> file2860280d275.cpp.err.txt’ had status 1

fx( 2L, 5 ) # should be 10
Error in fx(2L, 5) : could not find function “fx”

What is

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

?

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\

Sorry, I meant with a semi-colon instead of a colon

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