[Rcpp-devel] Seamless Rcpp gives errors with RcppArmadillo

Anirban Mukherjee anirban.mukherjee at gmail.com
Thu Jun 27 04:20:33 CEST 2013


inline + RcppArmadillo work on Mac. I tested the code in a Mac (Mountain
Lion 10.8.4) before posting. Install gfortran from:
http://r.research.att.com/gfortran-lion-5666-3.pkg. You can look here for
more information: http://r.research.att.com/tools/. If that does not work,
post in R-SIG-Mac.


On Wed, Jun 26, 2013 at 7:04 PM, Anirban Mukherjee <
anirban.mukherjee at gmail.com> wrote:

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


More information about the Rcpp-devel mailing list