<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. &nbsp;There were two suggestions: &nbsp;one was to upgrade my compiler, and the other was to find Linux&nbsp;on "another account somewhere at my large-enough university." &nbsp;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 &lt;- '</div><div><br></div><div>&nbsp;&nbsp; Rcpp::NumericMatrix xx(3,2);</div><div>&nbsp;&nbsp; int i;</div><div>&nbsp;&nbsp; int xsize = xx.nrow() * xx.ncol();</div><div>&nbsp;&nbsp;</div><div>&nbsp;&nbsp; for (i = 0; i &lt; xsize; i++) {</div><div>&nbsp;&nbsp; &nbsp; xx[i] = pow(i,2);</div><div>&nbsp;&nbsp; }</div><div><br></div><div>&nbsp;&nbsp; &nbsp; Rcpp::NumericMatrix::Column z1 = xx(_,0);</div><div>&nbsp;&nbsp; &nbsp; Rcpp::NumericVector z2 = xx(_,1);</div><div><br></div><div>&nbsp;&nbsp; return (Rcpp::wrap(xx));</div><div>'</div><div><br></div><div>func &lt;- cxxfunction(body=body,</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;plugin="Rcpp",</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;verbose=TRUE</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;)</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. &nbsp;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? &nbsp;The file t2.cpp is:</div><div><br></div><div>#include &lt;Rcpp.h&gt;</div><div><br></div><div>&nbsp;RcppExport SEXP test() {</div><div>&nbsp;&nbsp;</div><div>BEGIN_RCPP</div><div><br></div><div>&nbsp;&nbsp; Rcpp::NumericMatrix xx(3,2);</div><div>&nbsp;&nbsp; int i;</div><div>&nbsp;&nbsp; int xsize = xx.nrow() * xx.ncol();</div><div>&nbsp;&nbsp;</div><div>&nbsp;&nbsp; for (i = 0; i &lt; xsize; i++) {</div><div>&nbsp;&nbsp; &nbsp; xx[i] = pow(i,2);</div><div>&nbsp;&nbsp; }</div><div><br></div><div>&nbsp;&nbsp; &nbsp; Rcpp::NumericMatrix::Column z1 = xx(_,0);</div><div>&nbsp;&nbsp; &nbsp; Rcpp::NumericVector z2 = xx(_,1);</div><div><br></div><div>&nbsp;&nbsp; return (Rcpp::wrap(xx));</div><div><br></div><div>END_RCPP</div><div>&nbsp;&nbsp;</div><div>&nbsp;}&nbsp;</div><div><br></div><div>When I try to compile this, I get</div><div><br></div><div>equity&gt; g++44 -m64 -O0 -fPIC &nbsp; -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. &nbsp;So I hope we can agree that this is not a compiler issue and it is not a Mac issue. &nbsp;There's something about this underscore that is messing things up. &nbsp;(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. &nbsp;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,&nbsp;<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>