Rstan (2.8.1) expose_stan_functions compiles code on linux but not on windows

52 views
Skip to first unread message

Guido Biele

unread,
Nov 23, 2015, 9:29:18 AM11/23/15
to Stan users mailing list
Hello,

I am trying to expose a function in rstan and have a problem doing so on windows.

Session info and error message are below.
I am also attaching the stan code and the cpp code generated by stanc.

I tried to expose the same code on a linux machine, where it worked.
One difference between the linux and the windows rstan versions is 
though that on linux I installed rstan 2.8.1 a few weeks ago from the 
github repo, whereas on windows I installed rstan 2.8.1 today from cran.


Any help is appreciated!

Best, Guido


################## Error message ##################
g++ -m64 -I"C:/PROGRA~1/R/R-32~1.2/include"            -I"C:/PROGRA~1/R/R-32~1.2/library/Rcpp/include" -I"C:/PROGRA~1/R/R-32~1.2/library/STANHE~1/include" -I"C:/PROGRA~1/R/R-32~1.2/library/BH/include" -I"C:/PROGRA~1/R/R-32~1.2/library/RCPPEI~1/include" -I"C:/Users/gubi/AppData/Local/Temp/RtmpC29zbU"  -I"d:/RCompile/r-compiling/local/local320/include"     -O3 -c file16ac71211fa.cpp -o file16ac71211fa.o
file16ac71211fa.cpp: In function 'std::vector<Eigen::Matrix<double, -0x00000000000000001, -0x00000000000000001> > make_apc_info(const int&, const int&, const int&, const int&, const std::vector<int>&, const std::vector<int>&, const std::vector<int>&, const std::vector<int>&, const std::vector<int>&, const matrix_d&)':
file16ac71211fa.cpp:211:17: error: expected primary-expression before ')' token
file16ac71211fa.cpp:275:25: error: expected primary-expression before ')' token
file16ac71211fa.cpp:289:21: error: expected primary-expression before ')' token
make: *** [file16ac71211fa.o] Error 1
Warning message:
running command 'make -f "C:/PROGRA~1/R/R-32~1.2/etc/x64/Makeconf" -f "C:/PROGRA~1/R/R-32~1.2/share/make/winshlib.mk" -f "C:/Users/gubi/Documents/.R/Makevars" SHLIB_LDFLAGS='$(SHLIB_CXXLDFLAGS)' SHLIB_LD='$(SHLIB_CXXLD)' SHLIB="sourceCpp_1.dll" WIN=64 TCLBIN=64 OBJECTS="file16ac71211fa.o"' had status 2 
Error in Rcpp::sourceCpp(code = paste(lines, collapse = "\n")) : 
  Error 1 occurred building shared library.
Here is the C++ code that does not compile. Please report bug.
...

################## Session info ##################                                                                                                                                                                                                                                                                           
R version 3.2.2 (2015-08-14)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

locale:
[1] LC_COLLATE=Norwegian (Bokmål)_Norway.1252  LC_CTYPE=Norwegian (Bokmål)_Norway.1252   
[3] LC_MONETARY=Norwegian (Bokmål)_Norway.1252 LC_NUMERIC=C                              
[5] LC_TIME=Norwegian (Bokmål)_Norway.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] rstan_2.8.1   ggplot2_1.0.1

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.1         lattice_0.20-33     digest_0.6.8        MASS_7.3-44        
 [5] BH_1.58.0-1         grid_3.2.2          plyr_1.8.3          gtable_0.1.2       
 [9] stats4_3.2.2        magrittr_1.5        StanHeaders_2.8.0   scales_0.3.0       
[13] stringi_1.0-1       reshape2_1.4.1      Matrix_1.2-2        proto_0.3-10       
[17] tools_3.2.2         RcppEigen_0.3.2.5.1 stringr_1.0.0       munsell_0.4.2      
[21] inline_0.3.14       colorspace_1.2-6    gridExtra_2.0.0    
code.cpp
scale_vars.stan

Ben Goodrich

unread,
Nov 23, 2015, 10:42:04 AM11/23/15
to Stan users mailing list
On Monday, November 23, 2015 at 9:29:18 AM UTC-5, Guido Biele wrote:
I am trying to expose a function in rstan and have a problem doing so on windows.

I think it is not Windows-specific. I made a lot of late changes to expose_stan_functions to get it to work in other cases and now it seems to fail when the function being exposed has print() statements. It works for me if I comment all the print statements out of scale_vars.stan.

Ben
 

Guido Biele

unread,
Nov 23, 2015, 11:00:46 AM11/23/15
to Stan users mailing list
Thanks Ben!
Commenting out the print statements also made it work for me.
Guido

Bob Carpenter

unread,
Nov 23, 2015, 2:36:31 PM11/23/15
to stan-...@googlegroups.com
To get print to work, you need to pass in a stream with the
right name. There are no functions in Stan that print on their
own --- it's only the print statements.

Should I start generating a second Stan file that contains
pure double instantiations of all the template types that aren't
int? It wouldn't be hard to code generate. I'm reluctant to
put it at the top-level of the main Stan program output because
that's very poor programming practice. But I'd be OK generating
a second header file that calls the first that you could use.

I created an issue here:

https://github.com/stan-dev/stan/issues/1703

Should those functions catch all exceptions while they're at it?

I'd rather not have them swallow their print streams.

- Bob
> --
> You received this message because you are subscribed to the Google Groups "Stan users mailing list" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to stan-users+...@googlegroups.com.
> To post to this group, send email to stan-...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Ben Goodrich

unread,
Nov 23, 2015, 3:12:45 PM11/23/15
to Stan users mailing list
On Monday, November 23, 2015 at 2:36:31 PM UTC-5, Bob Carpenter wrote:
Should those functions catch all exceptions while they're at it?

I would say no. If there is an exception, R will throw an error.
 
I'd rather not have them swallow their print streams.

The print statements used to work, but I apparently broke them when fixing user-defined functions that do ODEs. It should be easy to fix in rstan.

Ben
Reply all
Reply to author
Forward
0 new messages