Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cannot compile rinside with armadillo examples

I am trying to compile the Rarmadillo example with Rinside and I keep getting:

In file included from rinside_arma0.cpp:8:0:
/usr/local64/opt/R-2.15.2/lib/R/library/RcppArmadillo/include/RcppArmadillo.h:26:6: error: #error "The file 'Rcpp.h' should not be included. Please correct to include only 'RcppArmadillo.h'."

I googled it but I keep getting the source code per se. Any ideas ?

The code is :

// -*- c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
//
// Simple example using Armadillo classes
//
// Copyright (C) 2012  Dirk Eddelbuettel and Romain Francois

#include <RInside.h>                    // for the embedded R via RInside
#include <RcppArmadillo.h>

int main(int argc, char *argv[]) {

    RInside R(argc, argv);      // create an embedded R instance

    std::string cmd = "diag(3)";    // create a Matrix in r 

    arma::mat m = Rcpp::as<arma::mat>(R.parseEval(cmd)); // parse, eval + return result

    std::cout << m << std::endl;    // and use Armadillo i/o  

    exit(0);
}

and compiled it using:

g++ -I/usr/local64/opt/R-2.15.2/lib/R/include -I/usr/local64/opt/R-2.15.2/lib/R/library/Rcpp/include -I"/usr/local64/opt/R-2.15.2/lib/R/library/RcppArmadillo/include"   -I/usr/local64/opt/R-2.15.2/lib/R/library/RInside/include -g -O2 -Wall -I/usr/local/include   rinside_arma0.cpp  -L/usr/local64/opt/R-2.15.2/lib/R/lib -lR  -lf77blas -latlas -llapack -L/usr/local64/opt/R-2.15.2/lib/R/library/Rcpp/lib -lRcpp -Wl,-rpath,/usr/local64/opt/R-2.15.2/lib/R/library/Rcpp/lib -L/usr/local64/opt/R-2.15.2/lib/R/library/RInside/lib -lRInside -Wl,-rpath,/usr/local64/opt/R-2.15.2/lib/R/library/RInside/lib  -o rinside_arma0
like image 803
madreblu Avatar asked Jul 04 '13 12:07

madreblu


1 Answers

The error you get is because Rcpp.h is included before RcppArmadillo.h, Rcpp.h is included by RInside.h.

For the magic that RcppArmadillo gives you, the file RcppArmadillo.h needs to be loaded before Rcpp.h. So I suggest you do this:

#include <RcppArmadillo.h>
#include <RInside.h>
like image 180
Romain Francois Avatar answered Sep 19 '22 00:09

Romain Francois