<div dir="ltr"><p class="">library(inline); library(RcppArmadillo)<br></p>
<p class="">rowSumsRA <- cxxfunction(signature(x = "numeric"), plugin="RcppArmadillo", body='return Rcpp::wrap(arma::sum(<span class="">as<arma::mat></span>(x),0));')</p><p class="">colSumsRA <- cxxfunction(signature(x = "numeric"), plugin="RcppArmadillo", body='return Rcpp::wrap(arma::sum(<span class="">as<arma::mat></span>(x),1));')</p>
<p class="" style>Anirban</p>
<div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Date: Wed, 26 Jun 2013 11:11:04 +0200<br>
From: John Swan <<a href="mailto:johnswan@spamcop.net">johnswan@spamcop.net</a>><br>
To: <a href="mailto:rcpp-devel@lists.r-forge.r-project.org">rcpp-devel@lists.r-forge.r-project.org</a><br>
Subject: [Rcpp-devel] Seamless Rcpp gives errors with RcppArmadillo<br>
Message-ID: <<a href="mailto:99384497-D7C4-4BC6-859E-C3FA1AB5FF7D@spamcop.net">99384497-D7C4-4BC6-859E-C3FA1AB5FF7D@spamcop.net</a>><br>
Content-Type: text/plain; charset="windows-1252"<br>
<br>
Hi,<br>
<br>
I just purchased Dirk's book on Seamless Rcpp and I'm finding it very useful.<br>
<br>
However, I'm having a strange error running RcppArmadillo inline, where the book examples seem to manage it effortlessly.<br>
I've been stuck on this for hours. Any help is most appreciated.<br>
<br>
I am using R 3.0 on Mac OS X Mountain Lion 10.8.4, sessionInfo output:<br>
> sessionInfo()<br>
R version 3.0.1 (2013-05-16)<br>
Platform: x86_64-apple-darwin10.8.0 (64-bit)<br>
<br>
locale:<br>
[1] en_GB.UTF-8/C/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8<br>
<br>
attached base packages:<br>
[1] stats graphics grDevices utils datasets methods base<br>
<br>
other attached packages:<br>
[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<br>
[8] Matrix_1.0-12 lattice_0.20-15<br>
<br>
loaded via a namespace (and not attached):<br>
[1] grid_3.0.1 tools_3.0.1<br>
<br>
<br>
I have the following in a source file (somefile.R):<br>
library(Rcpp)<br>
library(inline)<br>
library(RcppArmadillo)<br>
<br>
rowSumsRcppArmadilloFunction <- '<br>
arma::rowvec rowSumsRcppArmadillo(NumericMatrix x){<br>
arma::mat X = arma::mat(x.begin(), x.nrow(), x.ncol(), false);<br>
return arma::sum(X, 1);<br>
}'<br>
<br>
rowSumsRcppArmadillo <- cxxfunction(signature(),<br>
plugin="Rcpp",<br>
incl=rowSumsRcppArmadilloFunction,<br>
body='<br>
return Rcpp::wrap(rowSumsRcppArmadillo());<br>
')<br>
<br>
<br>
If I try to execute this in R console with the source command, I get:<br>
<br>
> source("/Users/me/Desktop/R/somefile.R")<br>
file29967eb06d23.cpp:20: error: ?arma? has not been declared<br>
file29967eb06d23.cpp:20: error: expected constructor, destructor, or type conversion before ?rowSumsRcppArmadillo?<br>
file29967eb06d23.cpp: In function ?SEXPREC* file29967eb06d23()?:<br>
file29967eb06d23.cpp:35: error: ?rowSumsRcppArmadillo? was not declared in this scope<br>
make: *** [file29967eb06d23.o] Error 1<br>
<br>
ERROR(s) during compilation: source code errors or compiler configuration errors!<br>
<br>
Program source:<br>
1:<br>
2: // includes from the plugin<br>
3:<br>
4: #include <Rcpp.h><br>
5:<br>
6:<br>
7: #ifndef BEGIN_RCPP<br>
8: #define BEGIN_RCPP<br>
9: #endif<br>
10:<br>
11: #ifndef END_RCPP<br>
12: #define END_RCPP<br>
13: #endif<br>
14:<br>
15: using namespace Rcpp;<br>
16:<br>
17:<br>
18: // user includes<br>
19:<br>
20: arma::rowvec rowSumsRcppArmadillo(NumericMatrix x){<br>
21: arma::mat X = arma::mat(x.begin(), x.nrow(), x.ncol(), false);<br>
22: return arma::sum(X, 1);<br>
23: }<br>
24:<br>
25: // declarations<br>
26: extern "C" {<br>
27: SEXP file29967eb06d23( ) ;<br>
28: }<br>
29:<br>
30: // definition<br>
31:<br>
32: SEXP file29967eb06d23( ){<br>
33: BEGIN_RCPP<br>
34:<br>
35: return Rcpp::wrap(rowSumsRcppArmadillo());<br>
36:<br>
37: END_RCPP<br>
38: }<br>
39:<br>
40:<br>
Error in compileCode(f, code, language = language, verbose = verbose) :<br>
Compilation ERROR, function(s)/method(s) not created! file29967eb06d23.cpp:20: error: ?arma? has not been declared<br>
file29967eb06d23.cpp:20: error: expected constructor, destructor, or type conversion before ?rowSumsRcppArmadillo?<br>
file29967eb06d23.cpp: In function ?SEXPREC* file29967eb06d23()?:<br>
file29967eb06d23.cpp:35: error: ?rowSumsRcppArmadillo? was not declared in this scope<br>
make: *** [file29967eb06d23.o] Error 1<br>
In addition: Warning message:<br>
running command '/Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB file29967eb06d23.cpp 2> file29967eb06d23.cpp.err.txt' had status 1<br>
<br>
I added these:<br>
20: #include <RcppArmadillo.h><br>
21: // [[Rcpp::depends(RcppArmadillo)]]<br>
22:<br>
23: // [[Rcpp::export]]<br>
24:<br>
25: arma::rowvec rowSumsRcppArmadillo(NumericMatrix x){<br>
26: arma::mat X = arma::mat(x.begin(), x.nrow(), x.ncol(), false);<br>
27: return arma::sum(X, 1);<br>
28: }<br>
<br>
But then I just get this error:<br>
Error in compileCode(f, code, language = language, verbose = verbose) :<br>
Compilation ERROR, function(s)/method(s) not created! file77e03dcff275.cpp:20:27: error: RcppArmadillo.h: No such file or directory<br>
file77e03dcff275.cpp:25: error: ?arma? has not been declared<br>
file77e03dcff275.cpp:25: error: expected constructor, destructor, or type conversion before ?rowSumsRcppArmadillo?<br>
file77e03dcff275.cpp: In function ?SEXPREC* file77e03dcff275()?:<br>
file77e03dcff275.cpp:40: error: ?rowSumsRcppArmadillo? was not declared in this scope<br>
make: *** [file77e03dcff275.o] Error 1<br>
In addition: Warning message:<br>
running command '/Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB file77e03dcff275.cpp 2> file77e03dcff275.cpp.err.txt' had status 1<br>
<br>
<br>
<br>
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:<br>
Error in sourceCpp("./R/somefile.R") :<br>
Error 1 occurred building shared library.<br>
<br>
WARNING: The tools required to build C++ code for R were not found.<br>
<br>
Please install Command Line Tools for XCode (or equivalent).<br>
<br>
ld: warning: directory not found for option '-L/usr/local/lib/gcc/i686-apple-darwin8/4.2.3/x86_64'<br>
ld: warning: directory not found for option '-L/usr/local/lib/x86_64'<br>
ld: warning: directory not found for option '-L/usr/local/lib/gcc/i686-apple-darwin8/4.2.3'<br>
ld: library not found for -lgfortran<br>
collect2: ld returned 1 exit status<br>
make: *** [sourceCpp_13326.so] Error 1<br>
<br>
<br>
The XCode command line tools *are* installed - I'm an iOS developer so I always make sure that they are there:<br>
<br>
John-MBPR:BDGraphSource johnswan$ which llvm-g++<br>
/usr/bin/llvm-g++<br>
John-MBPR:BDGraphSource johnswan$ llvm-g++ --version<br>
i686-apple-darwin11-llvm-g++-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)<br>
Copyright (C) 2007 Free Software Foundation, Inc.<br>
This is free software; see the source for copying conditions. There is NO<br>
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.<br>
<br>
<br>
Can anyone help?<br>
<br>
Thanks<br>
John<br>
-------------- next part --------------<br>
An HTML attachment was scrubbed...<br>
URL: <<a href="http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20130626/f34959cc/attachment-0001.html" target="_blank">http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20130626/f34959cc/attachment-0001.html</a>><br>
<br>
------------------------------<br></blockquote></div></div></div>