<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>Hi,</div><div><br></div><div>I just purchased Dirk's book on Seamless Rcpp and I'm finding it very useful.</div><div><br></div><div>However, I'm having a strange error running RcppArmadillo inline, where the book examples seem to manage it effortlessly.</div><div>I've been stuck on this for hours. Any help is most appreciated. </div><div><br></div><div>I am using R 3.0 on Mac OS X Mountain Lion 10.8.4, sessionInfo output:</div><div><div><font face="Menlo">> sessionInfo()</font></div><div><font face="Menlo">R version 3.0.1 (2013-05-16)</font></div><div><font face="Menlo">Platform: x86_64-apple-darwin10.8.0 (64-bit)</font></div><div><font face="Menlo"><br></font></div><div><font face="Menlo">locale:</font></div><div><font face="Menlo">[1] en_GB.UTF-8/C/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8</font></div><div><font face="Menlo"><br></font></div><div><font face="Menlo">attached base packages:</font></div><div><font face="Menlo">[1] stats graphics grDevices utils datasets methods base </font></div><div><font face="Menlo"><br></font></div><div><font face="Menlo">other attached packages:</font></div><div><font face="Menlo">[1] inline_0.3.12 RcppArmadillo_0.3.900.0 Rcpp_0.10.3 BDgraph_2.6 huge_1.2.4 MASS_7.3-26 igraph_0.6.5-2 </font></div><div><font face="Menlo">[8] Matrix_1.0-12 lattice_0.20-15 </font></div><div><font face="Menlo"><br></font></div><div><font face="Menlo">loaded via a namespace (and not attached):</font></div><div><font face="Menlo">[1] grid_3.0.1 tools_3.0.1</font></div></div><div><br></div><div><br></div><div>I have the following in a source file (somefile.R):</div><div><div><font face="Menlo">library(Rcpp)</font></div><div><font face="Menlo">library(inline)</font></div><div><font face="Menlo">library(RcppArmadillo)</font></div><div><font face="Menlo"><br></font></div><div><font face="Menlo">rowSumsRcppArmadilloFunction <- '</font></div><div><font face="Menlo">arma::rowvec rowSumsRcppArmadillo(NumericMatrix x){</font></div><div><font face="Menlo"> arma::mat X = arma::mat(x.begin(), x.nrow(), x.ncol(), false); </font></div><div><font face="Menlo"> return arma::sum(X, 1); </font></div><div><font face="Menlo">}'</font></div><div><font face="Menlo"><br></font></div><div><font face="Menlo">rowSumsRcppArmadillo <- cxxfunction(signature(),</font></div><div><font face="Menlo"><span class="Apple-tab-span" style="white-space: pre; "> </span>plugin="Rcpp",</font></div><div><font face="Menlo"><span class="Apple-tab-span" style="white-space: pre; "> </span>incl=rowSumsRcppArmadilloFunction,</font></div><div><font face="Menlo"><span class="Apple-tab-span" style="white-space: pre; "> </span>body='</font></div><div><font face="Menlo">return Rcpp::wrap(rowSumsRcppArmadillo());</font></div><div><font face="Menlo">')</font></div></div><div><br></div><div><br></div><div>If I try to execute this in R console with the source command, I get:</div><div><br></div><div><div><font face="Menlo">> source("/Users/me/Desktop/R/somefile.R")</font></div><div><font face="Menlo">file29967eb06d23.cpp:20: error: ‘arma’ has not been declared</font></div><div><font face="Menlo">file29967eb06d23.cpp:20: error: expected constructor, destructor, or type conversion before ‘rowSumsRcppArmadillo’</font></div><div><font face="Menlo">file29967eb06d23.cpp: In function ‘SEXPREC* file29967eb06d23()’:</font></div><div><font face="Menlo">file29967eb06d23.cpp:35: error: ‘rowSumsRcppArmadillo’ was not declared in this scope</font></div><div><font face="Menlo">make: *** [file29967eb06d23.o] Error 1</font></div><div><font face="Menlo"><br></font></div><div><font face="Menlo">ERROR(s) during compilation: source code errors or compiler configuration errors!</font></div><div><font face="Menlo"><br></font></div><div><font face="Menlo">Program source:</font></div><div><font face="Menlo"> 1: </font></div><div><font face="Menlo"> 2: // includes from the plugin</font></div><div><font face="Menlo"> 3: </font></div><div><font face="Menlo"> 4: #include <Rcpp.h></font></div><div><font face="Menlo"> 5: </font></div><div><font face="Menlo"> 6: </font></div><div><font face="Menlo"> 7: #ifndef BEGIN_RCPP</font></div><div><font face="Menlo"> 8: #define BEGIN_RCPP</font></div><div><font face="Menlo"> 9: #endif</font></div><div><font face="Menlo"> 10: </font></div><div><font face="Menlo"> 11: #ifndef END_RCPP</font></div><div><font face="Menlo"> 12: #define END_RCPP</font></div><div><font face="Menlo"> 13: #endif</font></div><div><font face="Menlo"> 14: </font></div><div><font face="Menlo"> 15: using namespace Rcpp;</font></div><div><font face="Menlo"> 16: </font></div><div><font face="Menlo"> 17: </font></div><div><font face="Menlo"> 18: // user includes</font></div><div><font face="Menlo"> 19: </font></div><div><font face="Menlo"> 20: arma::rowvec rowSumsRcppArmadillo(NumericMatrix x){</font></div><div><font face="Menlo"> 21: arma::mat X = arma::mat(x.begin(), x.nrow(), x.ncol(), false); </font></div><div><font face="Menlo"> 22: return arma::sum(X, 1); </font></div><div><font face="Menlo"> 23: }</font></div><div><font face="Menlo"> 24: </font></div><div><font face="Menlo"> 25: // declarations</font></div><div><font face="Menlo"> 26: extern "C" {</font></div><div><font face="Menlo"> 27: SEXP file29967eb06d23( ) ;</font></div><div><font face="Menlo"> 28: }</font></div><div><font face="Menlo"> 29: </font></div><div><font face="Menlo"> 30: // definition</font></div><div><font face="Menlo"> 31: </font></div><div><font face="Menlo"> 32: SEXP file29967eb06d23( ){</font></div><div><font face="Menlo"> 33: BEGIN_RCPP</font></div><div><font face="Menlo"> 34: </font></div><div><font face="Menlo"> 35: return Rcpp::wrap(rowSumsRcppArmadillo());</font></div><div><font face="Menlo"> 36: </font></div><div><font face="Menlo"> 37: END_RCPP</font></div><div><font face="Menlo"> 38: }</font></div><div><font face="Menlo"> 39: </font></div><div><font face="Menlo"> 40: </font></div><div><font face="Menlo">Error in compileCode(f, code, language = language, verbose = verbose) : </font></div><div><font face="Menlo"> Compilation ERROR, function(s)/method(s) not created! file29967eb06d23.cpp:20: error: ‘arma’ has not been declared</font></div><div><font face="Menlo">file29967eb06d23.cpp:20: error: expected constructor, destructor, or type conversion before ‘rowSumsRcppArmadillo’</font></div><div><font face="Menlo">file29967eb06d23.cpp: In function ‘SEXPREC* file29967eb06d23()’:</font></div><div><font face="Menlo">file29967eb06d23.cpp:35: error: ‘rowSumsRcppArmadillo’ was not declared in this scope</font></div><div><font face="Menlo">make: *** [file29967eb06d23.o] Error 1</font></div><div><font face="Menlo">In addition: Warning message:</font></div><div><font face="Menlo">running command '/Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB file29967eb06d23.cpp 2> file29967eb06d23.cpp.err.txt' had status 1 </font></div></div><div><br></div><div>I added these:</div><div><div> <font face="Menlo">20: #include <RcppArmadillo.h></font></div><div><font face="Menlo"> 21: // [[Rcpp::depends(RcppArmadillo)]]</font></div><div><font face="Menlo"> 22: </font></div><div><font face="Menlo"> 23: // [[Rcpp::export]]</font></div><div><font face="Menlo"> 24: </font></div><div><font face="Menlo"> 25: arma::rowvec rowSumsRcppArmadillo(NumericMatrix x){</font></div><div><font face="Menlo"> 26: arma::mat X = arma::mat(x.begin(), x.nrow(), x.ncol(), false); </font></div><div><font face="Menlo"> 27: return arma::sum(X, 1); </font></div><div><font face="Menlo"> 28: }</font></div></div><div><br></div><div>But then I just get this error:</div><div><div><font face="Menlo">Error in compileCode(f, code, language = language, verbose = verbose) : </font></div><div><font face="Menlo"> Compilation ERROR, function(s)/method(s) not created! file77e03dcff275.cpp:20:27: error: RcppArmadillo.h: No such file or directory</font></div><div><font face="Menlo">file77e03dcff275.cpp:25: error: ‘arma’ has not been declared</font></div><div><font face="Menlo">file77e03dcff275.cpp:25: error: expected constructor, destructor, or type conversion before ‘rowSumsRcppArmadillo’</font></div><div><font face="Menlo">file77e03dcff275.cpp: In function ‘SEXPREC* file77e03dcff275()’:</font></div><div><font face="Menlo">file77e03dcff275.cpp:40: error: ‘rowSumsRcppArmadillo’ was not declared in this scope</font></div><div><font face="Menlo">make: *** [file77e03dcff275.o] Error 1</font></div><div><font face="Menlo">In addition: Warning message:</font></div><div><font face="Menlo">running command '/Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB file77e03dcff275.cpp 2> file77e03dcff275.cpp.err.txt' had status 1 </font></div></div><div><br></div><div><br></div><div><br></div><div>So, I thought I'd try compilng it as a package, but when I try to call the package in R, I get errors like:</div><div><div><font face="Menlo">Error in sourceCpp("./R/</font><span style="font-family: Menlo; ">somefile.R</span><font face="Menlo">") : </font></div><div><font face="Menlo"> Error 1 occurred building shared library.</font></div><div><font face="Menlo"><br></font></div><div><font face="Menlo">WARNING: The tools required to build C++ code for R were not found.</font></div><div><font face="Menlo"><br></font></div><div><font face="Menlo">Please install Command Line Tools for XCode (or equivalent).</font></div><div><font face="Menlo"><br></font></div><div><font face="Menlo">ld: warning: directory not found for option '-L/usr/local/lib/gcc/i686-apple-darwin8/4.2.3/x86_64'</font></div><div><font face="Menlo">ld: warning: directory not found for option '-L/usr/local/lib/x86_64'</font></div><div><font face="Menlo">ld: warning: directory not found for option '-L/usr/local/lib/gcc/i686-apple-darwin8/4.2.3'</font></div><div><font face="Menlo">ld: library not found for -lgfortran</font></div><div><font face="Menlo">collect2: ld returned 1 exit status</font></div><div><font face="Menlo">make: *** [sourceCpp_13326.so] Error 1</font></div></div><div><br></div><div><br></div><div>The XCode command line tools *are* installed - I'm an iOS developer so I always make sure that they are there:</div><div><br></div><div><div><font face="Menlo">John-MBPR:BDGraphSource johnswan$ which llvm-g++</font></div><div><font face="Menlo">/usr/bin/llvm-g++</font></div><div><font face="Menlo">John-MBPR:BDGraphSource johnswan$ llvm-g++ --version </font></div><div><font face="Menlo">i686-apple-darwin11-llvm-g++-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)</font></div><div><font face="Menlo">Copyright (C) 2007 Free Software Foundation, Inc.</font></div><div><font face="Menlo">This is free software; see the source for copying conditions. There is NO</font></div><div><font face="Menlo">warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.</font></div><div><br></div></div><div><br></div><div>Can anyone help?</div><div><br></div><div>Thanks</div><div>John</div></body></html>