5

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
madreblu
  • 373
  • 5
  • 15
  • Can you put the code in rinside_arma0.cpp and the command you used to compile it – dickoa Jul 04 '13 at 12:10
  • You should consider using a Makefile to simplify your compilation process and make it more easier to understand. Look for example at `/usr/local64/opt/R-2.15.2/lib/R/library/RInside/examples/armadillo/Makefile`. Which platform do you use ? – dickoa Jul 04 '13 at 12:49
  • I do use the Makefile. I just copy-pasted the compile command used by the makefile as you requested. Linux PC – madreblu Jul 04 '13 at 13:04
  • I tried and I have also a problem...as soon as I find a solution, I'll post it. Meanwhile I hope that @eddelbuettel will read this question and propose you a proper solution. Sorry – dickoa Jul 04 '13 at 13:07
  • Have you tried including RcppArmadillo.h before Rinside.h ? – Romain Francois Jul 04 '13 at 22:34
  • OMG that worked ! Put it as an answer and I will accept it. – madreblu Jul 05 '13 at 09:40

1 Answers1

10

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>
Romain Francois
  • 17,432
  • 3
  • 51
  • 77
  • 1
    The same is true for the second example in that directory as well, and the reordering fix was committed in April -- we just have not released RInside since. – Dirk Eddelbuettel Jul 07 '13 at 21:19