A simple hello world program using Stan Math Error

247 views
Skip to first unread message

Ivan Aliaga

unread,
Nov 27, 2016, 11:10:40 PM11/27/16
to Stan users mailing list

Hello every world Stan R.

I have problem with Rstan and package  Rcpp when installation is newbie
i instaled the follow packages

>install.packages("StanHeader",dep=TRUE)
>install.packages("rstantools",dep=TRUE)
>devtools::install_github("stan-dev/rstan", ref = "develop", subdir = "rstan/rstan", build_vignettes = TRUE, dependencies = TRUE)


a simple "CodeStanPrueba.cpp" file is.

#include <stan/math.hpp>
#include <iostream>
// [[Rcpp::export]]
int simple() {
  std::cout << "log normal(1 | 2, 3)=" 
            << stan::math::normal_log(1, 2, 5) 
            << std::endl;
}

when execute 
>Rcpp::sourceCpp("CodeStanPrueba.cpp")
C:/Rtools/mingw_64/bin/g++  -I"C:/PROGRA~1/R/R-33~1.2/include" -DNDEBUG     -I"C:/Users/IVANAL~1/DOCUME~1/R/WIN-LI~1/3.3/Rcpp/include" -I"C:/Users/IVANAL~1/Desktop/BAYESI~1" -I"d:/Compiler/gcc-4.9.3/local330/include"     -O3 -mtune=native -march=native -Wno-unused-variable -Wno-unused-function -lrt -c CodeStanPrueba.cpp -o CodeStanPrueba.o
CodeStanPrueba.cpp:1:25: fatal error: stan/math.hpp: No such file or directory
 #include <stan/math.hpp>
                         ^
compilation terminated.
make: *** [CodeStanPrueba.o] Error 1
Warning message:
comando ejecutado 'make -f "C:/PROGRA~1/R/R-33~1.2/etc/x64/Makeconf" -f "C:/PROGRA~1/R/R-33~1.2/share/make/winshlib.mk" -f "C:\Users\IVAN ALIAGA\Documents/.R/Makevars" SHLIB_LDFLAGS='$(SHLIB_CXXLDFLAGS)' SHLIB_LD='$(SHLIB_CXXLD)' SHLIB="sourceCpp_4.dll" WIN=64 TCLBIN=64 OBJECTS="CodeStanPrueba.o"' tiene estatus 2 
Error in Rcpp::sourceCpp("CodeStanPrueba.cpp") : 
  Error 1 occurred building shared library.

> version

platform       x86_64-w64-mingw32          
arch           x86_64                      
os             mingw32                     
system         x86_64, mingw32             
status                                     
major          3                           
minor          3.2                         
year           2016                        
month          10                          
day            31                          
svn rev        71607                       
language       R                           
version.string R version 3.3.2 (2016-10-31)
nickname       Sincere Pumpkin Patch

> system("g++ -v")

Using built-in specs.
COLLECT_GCC=c:\Rtools\mingw_32\bin\G__~1.EXE
COLLECT_LTO_WRAPPER=c:/Rtools/mingw_32/bin/../libexec/gcc/i686-w64-mingw32/4.9.3/lto-wrapper.exe
Target: i686-w64-mingw32
Configured with: ../../../src/gcc-4.9.3/configure --host=i686-w64-mingw32 --build=i686-w64-mingw32 --target=i686-w64-mingw32 --prefix=/mingw32 --with-sysroot=/home/Jeroen/mingw-gcc-4.9.3/i686-493-posix-dwarf-rt_v3-s/mingw32 --with-gxx-include-dir=/mingw32/i686-w64-mingw32/include/c++ --enable-static --disable-shared --disable-multilib --enable-languages=c,c++,fortran,lto --enable-libstdcxx-time=yes --enable-threads=posix --enable-libgomp --enable-libatomic --enable-lto --enable-graphite --enable-checking=release --enable-fully-dynamic-string --enable-version-specific-runtime-libs --disable-sjlj-exceptions --with-dwarf2 --disable-isl-version-check --disable-cloog-version-check --disable-libstdcxx-pch --disable-libstdcxx-debug --enable-bootstrap --disable-rpath --disable-win32-registry --disable-nls --disable-werror --disable-symvers --with-gnu-as --with-gnu-ld --with-arch=i686 --with-tune=generic --with-libiconv --with-system-zlib --with-gmp=/home/Jeroen/mingw-gcc-4.9.3/prerequisites/i686-w64-mingw32-static --with-mpfr=/home/Jeroen/mingw-gcc-4.9.3/prerequisites/i686-w64-mingw32-static --with-mpc=/home/Jeroen/mingw-gcc-4.9.3/prerequisites/i686-w64-mingw32-static --with-isl=/home/Jeroen/mingw-gcc-4.9.3/prerequisites/i686-w64-mingw32-static --with-cloog=/home/Jeroen/mingw-gcc-4.9.3/prerequisites/i686-w64-mingw32-static --enable-cloog-backend=isl --with-pkgversion='i686-posix-dwarf, Built by MinGW-W64 project' --with-bugurl=http://sourceforge.net/projects/mingw-w64 CFLAGS='-O2 -pipe -I/home/Jeroen/mingw-gcc-4.9.3/i686-493-posix-dwarf-rt_v3-s/mingw32/opt/include -I/home/Jeroen/mingw-gcc-4.9.3/prerequisites/i686-zlib-static/include -I/home/Jeroen/mingw-gcc-4.9.3/prerequisites/i686-w64-mingw32-static/include' CXXFLAGS='-O2 -pipe -I/home/Jeroen/mingw-gcc-4.9.3/i686-493-posix-dwarf-rt_v3-s/mingw32/opt/include -I/home/Jeroen/mingw-gcc-4.9.3/prerequisites/i686-zlib-static/include -I/home/Jeroen/mingw-gcc-4.9.3/prerequisites/i686-w64-mingw32-static/include' CPPFLAGS= LDFLAGS='-pipe -L/home/Jeroen/mingw-gcc-4.9.3/i686-493-posix-dwarf-rt_v3-s/mingw32/opt/lib -L/home/Jeroen/mingw-gcc-4.9.3/prerequisites/i686-zlib-static/lib -L/home/Jeroen/mingw-gcc-4.9.3/prerequisites/i686-w64-mingw32-static/lib -Wl,--large-address-aware'
Thread model: posix
gcc version 4.9.3 (i686-posix-dwarf, Built by MinGW-W64 project) 

> sessionInfo()

R version 3.3.2 (2016-10-31)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 8.1 x64 (build 9600)

locale:
[1] LC_COLLATE=Spanish_Bolivia.1252  LC_CTYPE=Spanish_Bolivia.1252   
[3] LC_MONETARY=Spanish_Bolivia.1252 LC_NUMERIC=C                    
[5] LC_TIME=Spanish_Bolivia.1252    

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

other attached packages:
[1] rstan_2.12.1         StanHeaders_2.12.0-1 ggplot2_2.2.0       

loaded via a namespace (and not attached):
 [1] colorspace_1.2-7 scales_0.4.1     assertthat_0.1   lazyeval_0.2.0  
 [5] plyr_1.8.4       tools_3.3.2      inline_0.3.14    gtable_0.2.0    
 [9] tibble_1.2       gridExtra_2.2.1  Rcpp_0.12.8      grid_3.3.2      
[13] stats4_3.3.2     munsell_0.4.3   

I think in https://github.com/stan-dev/math  the result is: 
> cd /path/to/foo
> clang++ -I /path/to/stan-math -I /path/to/Eigen -I /path/to/boost foo.cpp  -I /path/to/cvodes
> ./a.out
log normal(1 | 2, 3)=-2.07311

Ben Goodrich

unread,
Nov 27, 2016, 11:36:06 PM11/27/16
to Stan users mailing list
On Sunday, November 27, 2016 at 11:10:40 PM UTC-5, Ivan Aliaga wrote:
a simple "CodeStanPrueba.cpp" file is.

#include <stan/math.hpp>
#include <iostream>
// [[Rcpp::export]]
int simple() {
  std::cout << "log normal(1 | 2, 3)=" 
            << stan::math::normal_log(1, 2, 5) 
            << std::endl;
}

You need

// [[Rcpp::depends(rstan)]]

at the top (and to actually return an int).

Ben

Ivan Aliaga

unread,
Nov 28, 2016, 11:17:37 AM11/28/16
to Stan users mailing list
Sorry, ok thanks, but  a modify file CodeStanPrueba.cpp

#include <stan/math.hpp>
#include <iostream>

// [[Rcpp::export]]
// [[Rcpp::depends(rstan)]]
int simple() {
  std::cout << "log normal(1 | 2, 3)=" 
            << stan::math::normal_log(1, 2, 3) 
            << std::endl;
}

 >Rcpp::sourceCpp("CodeStanPrueba.cpp")
C:/Rtools/mingw_64/bin/g++  -I"C:/PROGRA~1/R/R-33~1.2/include" -DNDEBUG   -I"C:/Users/IVAN ALIAGA/Documents/R/win-library/3.3/Rcpp/include/"  -I"C:/Users/IVAN ALIAGA/Documents/R/win-library/3.3/RcppEigen/include/"  -I"C:/Users/IVAN ALIAGA/Documents/R/win-library/3.3/RcppEigen/include/unsupported"  -I"C:/Users/IVAN ALIAGA/Documents/R/win-library/3.3/rstan/include/boost_not_in_BH" -I"C:/Users/IVAN ALIAGA/Documents/R/win-library/3.3/BH/include" -I"C:/Users/IVAN ALIAGA/Documents/R/win-library/3.3/StanHeaders/include/src/"  -I"C:/Users/IVAN ALIAGA/Documents/R/win-library/3.3/StanHeaders/include/"  -I"C:/Users/IVAN ALIAGA/Documents/R/win-library/3.3/rstan/include" -DEIGEN_NO_DEBUG  -DBOOST_RESULT_OF_USE_TR1 -DBOOST_NO_DECLTYPE -DBOOST_DISABLE_ASSERTS    -I"C:/Users/IVANAL~1/DOCUME~1/R/WIN-LI~1/3.3/Rcpp/include" -I"C:/Users/IVANAL~1/DOCUME~1/R/WIN-LI~1/3.3/rstan/include" -I"C:/Users/IVANAL~1/Desktop/BAYESI~1" -I"d:/Compiler/gcc-4.9.3/local330/include"     -O2 -Wall  -mtune=core2 -c CodeStanPrueba.cpp -o CodeStanPrueba.o
In file included from C:/Users/IVAN ALIAGA/Documents/R/win-library/3.3/BH/include/boost/multi_array/base.hpp:28:0,
                 from C:/Users/IVAN ALIAGA/Documents/R/win-library/3.3/BH/include/boost/multi_array.hpp:21,
                 from C:/Users/IVAN ALIAGA/Documents/R/win-library/3.3/BH/include/boost/numeric/odeint/util/multi_array_adaption.hpp:29,
                 from C:/Users/IVAN ALIAGA/Documents/R/win-library/3.3/BH/include/boost/numeric/odeint.hpp:61,
                 from C:/Users/IVAN ALIAGA/Documents/R/win-library/3.3/StanHeaders/include/stan/math/prim/arr/functor/integrate_ode_rk45.hpp:13,
                 from C:/Users/IVAN ALIAGA/Documents/R/win-library/3.3/StanHeaders/include/stan/math/prim/arr.hpp:36,
                 from C:/Users/IVAN ALIAGA/Documents/R/win-library/3.3/StanHeaders/include/stan/math/prim/mat.hpp:235,
                 from C:/Users/IVAN ALIAGA/Documents/R/win-library/3.3/StanHeaders/include/stan/math/rev/mat.hpp:9,
                 from C:/Users/IVAN ALIAGA/Documents/R/win-library/3.3/StanHeaders/include/stan/math.hpp:4,
                 from CodeStanPrueba.cpp:1:
C:/Users/IVAN ALIAGA/Documents/R/win-library/3.3/BH/include/boost/multi_array/concept_checks.hpp: In static member function 'static void boost::multi_array_concepts::detail::idgen_helper<N>::call(Array&, const IdxGen&, Call_Type)':
C:/Users/IVAN ALIAGA/Documents/R/win-library/3.3/BH/include/boost/multi_array/concept_checks.hpp:42:43: warning: typedef 'index_range' locally defined but not used [-Wunused-local-typedefs]
       typedef typename Array::index_range index_range;
                                           ^
C:/Users/IVAN ALIAGA/Documents/R/win-library/3.3/BH/include/boost/multi_array/concept_checks.hpp:43:37: warning: typedef 'index' locally defined but not used [-Wunused-local-typedefs]
       typedef typename Array::index index;
                                     ^
C:/Users/IVAN ALIAGA/Documents/R/win-library/3.3/BH/include/boost/multi_array/concept_checks.hpp: In static member function 'static void boost::multi_array_concepts::detail::idgen_helper<0ull>::call(Array&, const IdxGen&, Call_Type)':
C:/Users/IVAN ALIAGA/Documents/R/win-library/3.3/BH/include/boost/multi_array/concept_checks.hpp:53:43: warning: typedef 'index_range' locally defined but not used [-Wunused-local-typedefs]
       typedef typename Array::index_range index_range;
                                           ^
C:/Users/IVAN ALIAGA/Documents/R/win-library/3.3/BH/include/boost/multi_array/concept_checks.hpp:54:37: warning: typedef 'index' locally defined but not used [-Wunused-local-typedefs]
       typedef typename Array::index index;
                                     ^
CodeStanPrueba.cpp: In function 'int simple()':
CodeStanPrueba.cpp:10:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
CodeStanPrueba.cpp: At global scope:
CodeStanPrueba.cpp:15:50: error: expected primary-expression before 'simple'
 RcppExport SEXP sourceCpp_1_[[Rcpp::depends(SEXP simple(SEXP) {
                                                  ^
CodeStanPrueba.cpp:19:43: warning: c++11 attributes only available with -std=c++11 or -std=gnu++11
     Rcpp::traits::input_parameter< rstan)]] int >::type simple((simple(SEXP);
                                           ^
CodeStanPrueba.cpp:19:45: error: expected initializer before 'int'
     Rcpp::traits::input_parameter< rstan)]] int >::type simple((simple(SEXP);
                                             ^
CodeStanPrueba.cpp:20:5: error: 'rcpp_result_gen' does not name a type
     rcpp_result_gen = Rcpp::wrap([[Rcpp::depends(simple());
     ^
CodeStanPrueba.cpp:21:5: error: expected unqualified-id before 'return'
     return rcpp_result_gen;
     ^
In file included from C:/Users/IVAN ALIAGA/Documents/R/win-library/3.3/Rcpp/include/Rcpp/r/headers.h:50:0,
                 from C:/Users/IVAN ALIAGA/Documents/R/win-library/3.3/Rcpp/include/RcppCommon.h:29,
                 from C:/Users/IVAN ALIAGA/Documents/R/win-library/3.3/Rcpp/include/Rcpp.h:27,
                 from CodeStanPrueba.cpp:12:
C:/Users/IVAN ALIAGA/Documents/R/win-library/3.3/Rcpp/include/Rcpp/macros/macros.h:38:5: error: expected declaration before '}' token
     }                                                                                            \
     ^
C:/Users/IVAN ALIAGA/Documents/R/win-library/3.3/Rcpp/include/Rcpp/macros/macros.h:60:18: note: in expansion of macro 'VOID_END_RCPP'
 #define END_RCPP VOID_END_RCPP return R_NilValue;
                  ^
CodeStanPrueba.cpp:22:1: note: in expansion of macro 'END_RCPP'
 END_RCPP
 ^
In file included from C:/Users/IVAN ALIAGA/Documents/R/win-library/3.3/StanHeaders/include/stan/math/rev/core/operator_unary_plus.hpp:7:0,
                 from C:/Users/IVAN ALIAGA/Documents/R/win-library/3.3/StanHeaders/include/stan/math/rev/core.hpp:34,
                 from C:/Users/IVAN ALIAGA/Documents/R/win-library/3.3/StanHeaders/include/stan/math/rev/mat.hpp:4,
                 from C:/Users/IVAN ALIAGA/Documents/R/win-library/3.3/StanHeaders/include/stan/math.hpp:4,
                 from CodeStanPrueba.cpp:1:
C:/Users/IVAN ALIAGA/Documents/R/win-library/3.3/StanHeaders/include/stan/math/prim/scal/fun/constants.hpp:65:18: warning: 'stan::math::NEGATIVE_EPSILON' defined but not used [-Wunused-variable]
     const double NEGATIVE_EPSILON
                  ^
In file included from C:/Users/IVAN ALIAGA/Documents/R/win-library/3.3/StanHeaders/include/stan/math/rev/core.hpp:42:0,
                 from C:/Users/IVAN ALIAGA/Documents/R/win-library/3.3/StanHeaders/include/stan/math/rev/mat.hpp:4,
                 from C:/Users/IVAN ALIAGA/Documents/R/win-library/3.3/StanHeaders/include/stan/math.hpp:4,
                 from CodeStanPrueba.cpp:1:
C:/Users/IVAN ALIAGA/Documents/R/win-library/3.3/StanHeaders/include/stan/math/rev/core/set_zero_all_adjoints.hpp:14:17: warning: 'void stan::math::set_zero_all_adjoints()' defined but not used [-Wunused-function]
     static void set_zero_all_adjoints() {
                 ^
make: *** [CodeStanPrueba.o] Error 1
Warning message:
comando ejecutado 'make -f "C:/PROGRA~1/R/R-33~1.2/etc/x64/Makeconf" -f "C:/PROGRA~1/R/R-33~1.2/share/make/winshlib.mk" -f "C:\Users\IVAN ALIAGA\Documents/.R/Makevars" SHLIB_LDFLAGS='$(SHLIB_CXXLDFLAGS)' SHLIB_LD='$(SHLIB_CXXLD)' SHLIB="sourceCpp_2.dll" WIN=64 TCLBIN=64 OBJECTS="CodeStanPrueba.o"' tiene estatus 2 
Error in Rcpp::sourceCpp("CodeStanPrueba.cpp") : 
Error 1 occurred building shared library.

Ben Goodrich

unread,
Nov 28, 2016, 1:32:10 PM11/28/16
to Stan users mailing list
On Monday, November 28, 2016 at 11:17:37 AM UTC-5, Ivan Aliaga wrote:
Sorry, ok thanks, but  a modify file CodeStanPrueba.cpp

#include <stan/math.hpp>
#include <iostream>

// [[Rcpp::export]]
// [[Rcpp::depends(rstan)]]
int simple() {
  std::cout << "log normal(1 | 2, 3)=" 
            << stan::math::normal_log(1, 2, 3) 
            << std::endl;
}

// [[Rcpp::depends(rstan)]]


#include <stan/math.hpp>
#include <iostream>
// [[Rcpp::export]]
int simple() {
  std::cout << "log normal(1 | 2, 3)="
            << stan::math::normal_log(1, 2, 5)
            << std::endl;
  return 0;
}

Ben

Ivan Aliaga

unread,
Dec 9, 2016, 10:00:01 AM12/9/16
to Stan users mailing list
Thanks Ben  very good!!!
But it is normal to see these messages, of course the result is good as published.

>Rcpp::sourceCpp("CodeStanPrueba.cpp")
In file included from C:/Users/IVAN ALIAGA/Documents/R/win-library/3.3/BH/include/boost/multi_array/base.hpp:28:0,
                 from C:/Users/IVAN ALIAGA/Documents/R/win-library/3.3/BH/include/boost/multi_array.hpp:21,
                 from C:/Users/IVAN ALIAGA/Documents/R/win-library/3.3/BH/include/boost/numeric/odeint/util/multi_array_adaption.hpp:29,
                 from C:/Users/IVAN ALIAGA/Documents/R/win-library/3.3/BH/include/boost/numeric/odeint.hpp:61,
                 from C:/Users/IVAN ALIAGA/Documents/R/win-library/3.3/StanHeaders/include/stan/math/prim/arr/functor/integrate_ode_rk45.hpp:13,
                 from C:/Users/IVAN ALIAGA/Documents/R/win-library/3.3/StanHeaders/include/stan/math/prim/arr.hpp:36,
                 from C:/Users/IVAN ALIAGA/Documents/R/win-library/3.3/StanHeaders/include/stan/math/prim/mat.hpp:235,
                 from C:/Users/IVAN ALIAGA/Documents/R/win-library/3.3/StanHeaders/include/stan/math/rev/mat.hpp:9,
                 from C:/Users/IVAN ALIAGA/Documents/R/win-library/3.3/StanHeaders/include/stan/math.hpp:4,
                 from CodeStanPrueba.cpp:2:
C:/Users/IVAN ALIAGA/Documents/R/win-library/3.3/BH/include/boost/multi_array/concept_checks.hpp: In static member function 'static void boost::multi_array_concepts::detail::idgen_helper<N>::call(Array&, const IdxGen&, Call_Type)':
C:/Users/IVAN ALIAGA/Documents/R/win-library/3.3/BH/include/boost/multi_array/concept_checks.hpp:42:43: warning: typedef 'index_range' locally defined but not used [-Wunused-local-typedefs]
       typedef typename Array::index_range index_range;
                                           ^
C:/Users/IVAN ALIAGA/Documents/R/win-library/3.3/BH/include/boost/multi_array/concept_checks.hpp:43:37: warning: typedef 'index' locally defined but not used [-Wunused-local-typedefs]
       typedef typename Array::index index;
                                     ^
C:/Users/IVAN ALIAGA/Documents/R/win-library/3.3/BH/include/boost/multi_array/concept_checks.hpp: In static member function 'static void boost::multi_array_concepts::detail::idgen_helper<0ull>::call(Array&, const IdxGen&, Call_Type)':
C:/Users/IVAN ALIAGA/Documents/R/win-library/3.3/BH/include/boost/multi_array/concept_checks.hpp:53:43: warning: typedef 'index_range' locally defined but not used [-Wunused-local-typedefs]
       typedef typename Array::index_range index_range;
                                           ^
C:/Users/IVAN ALIAGA/Documents/R/win-library/3.3/BH/include/boost/multi_array/concept_checks.hpp:54:37: warning: typedef 'index' locally defined but not used [-Wunused-local-typedefs]
       typedef typename Array::index index;
                                     ^
In file included from C:/Users/IVAN ALIAGA/Documents/R/win-library/3.3/StanHeaders/include/stan/math/rev/core.hpp:42:0,
                 from C:/Users/IVAN ALIAGA/Documents/R/win-library/3.3/StanHeaders/include/stan/math/rev/mat.hpp:4,
                 from C:/Users/IVAN ALIAGA/Documents/R/win-library/3.3/StanHeaders/include/stan/math.hpp:4,
                 from CodeStanPrueba.cpp:2:
C:/Users/IVAN ALIAGA/Documents/R/win-library/3.3/StanHeaders/include/stan/math/rev/core/set_zero_all_adjoints.hpp: At global scope:
C:/Users/IVAN ALIAGA/Documents/R/win-library/3.3/StanHeaders/include/stan/math/rev/core/set_zero_all_adjoints.hpp:14:17: warning: 'void stan::math::set_zero_all_adjoints()' defined but not used [-Wunused-function]
     static void set_zero_all_adjoints() {
                 ^

Ben Goodrich

unread,
Dec 9, 2016, 10:46:39 AM12/9/16
to Stan users mailing list
On Friday, December 9, 2016 at 10:00:01 AM UTC-5, Ivan Aliaga wrote:
Thanks Ben  very good!!!
But it is normal to see these messages, of course the result is good as published.

Reply all
Reply to author
Forward
0 new messages