<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>Hello, again.</div><div><br></div><div>A couple of weeks ago, I posted a problem in compiling and running one of the examples from the Rcpp-quickref pdf. There were two suggestions: one was to upgrade my compiler, and the other was to find Linux on "another account somewhere at my large-enough university." I have done both (now using g++ 4.4 on Red Hat Enterprise Linux), and have the same problem. (The version of Rcpp is 0.9.3)</div><div><br></div><div>Consider the following code, executed using the inline package:</div><div><br></div><div><div>library(Rcpp)</div><div>library(inline)</div><div><br></div><div>body <- '</div><div><br></div><div> Rcpp::NumericMatrix xx(3,2);</div><div> int i;</div><div> int xsize = xx.nrow() * xx.ncol();</div><div> </div><div> for (i = 0; i < xsize; i++) {</div><div> xx[i] = pow(i,2);</div><div> }</div><div><br></div><div> Rcpp::NumericMatrix::Column z1 = xx(_,0);</div><div> Rcpp::NumericVector z2 = xx(_,1);</div><div><br></div><div> return (Rcpp::wrap(xx));</div><div>'</div><div><br></div><div>func <- cxxfunction(body=body,</div><div> plugin="Rcpp",</div><div> verbose=TRUE</div><div> )</div></div><div><br></div><div>Dirk ran this on his Debian system, and I can confirm that this works fine on my Red Hat system. No problems so far.</div><div><br></div><div><br></div><div>Now, what if I want to take this code into production, and don't want to use the inline package? The file t2.cpp is:</div><div><br></div><div>#include <Rcpp.h></div><div><br></div><div> RcppExport SEXP test() {</div><div> </div><div>BEGIN_RCPP</div><div><br></div><div> Rcpp::NumericMatrix xx(3,2);</div><div> int i;</div><div> int xsize = xx.nrow() * xx.ncol();</div><div> </div><div> for (i = 0; i < xsize; i++) {</div><div> xx[i] = pow(i,2);</div><div> }</div><div><br></div><div> Rcpp::NumericMatrix::Column z1 = xx(_,0);</div><div> Rcpp::NumericVector z2 = xx(_,1);</div><div><br></div><div> return (Rcpp::wrap(xx));</div><div><br></div><div>END_RCPP</div><div> </div><div> } </div><div><br></div><div>When I try to compile this, I get</div><div><br></div><div>equity> g++44 -m64 -O0 -fPIC -Wall -I/usr/local/include -I/usr/include/R -I/usr/lib64/R/library/Rcpp/include -c t2.cpp -o t2.o</div><div><br></div><div><div>t2.cpp: In function ‘SEXPREC* test()’:</div><div>t2.cpp:17: error: ‘_’ was not declared in this scope</div><div>t2.cpp:17: warning: unused variable ‘z1’</div><div>t2.cpp:18: warning: unused variable ‘z2’</div></div><div><br></div><div>I get this kind of error on both Mac and Linux, using g++ or the Intel compiler. So I hope we can agree that this is not a compiler issue and it is not a Mac issue. There's something about this underscore that is messing things up. (Incidentally, this fails on the Mac when using inline as well, but that appears to be yet another issue).</div><div><br></div><div>I tried to make this example as small and replicable as possible. If you need me to present this problem another way, please let me know.</div><div><br></div><div>Thanks,</div><div><br></div><div>Michael</div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><br><div>
<div>-------------------------------------------<br>Michael Braun<br>Homer A. Burnell (1928) Career Development Professor, <br><span class="Apple-tab-span" style="white-space: pre; ">        </span>and Assistant Professor of Management Science (Marketing Group)<br>MIT Sloan School of Management<br>100 Main St.., E62-535<br>Cambridge, MA 02139<br><a href="mailto:braunm@mit.edu">braunm@mit.edu</a><br>617-253-3436</div><div><br></div><br class="Apple-interchange-newline">
</div>
<br></body></html>