From murdoch.duncan at gmail.com  Tue Dec  6 15:27:46 2011
From: murdoch.duncan at gmail.com (Duncan Murdoch)
Date: Tue, 06 Dec 2011 09:27:46 -0500
Subject: [Rd] RcppArmadillo compilation error: R CMD SHLIB returns
 status 1
In-Reply-To: <OF2D585061.05B2DE60-ONC125795D.0064F3D4-C125795D.0064F3D9@diw.de>
References: <OF2D585061.05B2DE60-ONC125795D.0064F3D4-C125795D.0064F3D9@diw.de>
Message-ID: <4EDE2662.1070606@gmail.com>

On 05/12/2011 1:22 PM, Paul Viefers wrote:
> Dear all,
>
> running the example by D. Eddebuettel (http://dirk.eddelbuettel.com/blog/2011/04/23/) I get an error message. Specifically, the R code I was taking from the above example is
>
> ### BEGIN EXAMPLE ###
>
> suppressMessages(require(RcppArmadillo))
> suppressMessages(require(Rcpp))
> suppressMessages(require(inline))
> code<- '
>     arma::mat coeff = Rcpp::as<arma::mat>(a);
>     arma::mat errors = Rcpp::as<arma::mat>(e);
>     int m = errors.n_rows; int n = errors.n_cols;
>     arma::mat simdata(m,n);
>     simdata.row(0) = arma::zeros<arma::mat>(1,n);
>     for (int row=1; row<m; row++) {
>       simdata.row(row) = simdata.row(row-1)*trans(coeff)+errors.row(row);
>     }
>     return Rcpp::wrap(simdata);
>   '
> ## create the compiled function
> rcppSim<- cxxfunction(signature(a="numeric",e="numeric"),
>                          code,plugin="RcppArmadillo")
>
> ### END OF EXAMPLE ###
>
> Executing this inside R, returned the following:
>
> ERROR(s) during compilation: source code errors or compiler configuration errors!
>
> Program source:
>    1:
>    2: // includes from the plugin
>    3: #include<RcppArmadillo.h>
>    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:
>   21: // declarations
>   22: extern "C" {
>   23: SEXP file33765791( SEXP a, SEXP e) ;
>   24: }
>   25:
>   26: // definition
>   27:
>   28: SEXP file33765791( SEXP a, SEXP e ){
>   29: BEGIN_RCPP
>   30:
>   31:    arma::mat coeff = Rcpp::as<arma::mat>(a);
>   32:    arma::mat errors = Rcpp::as<arma::mat>(e);
>   33:    int m = errors.n_rows; int n = errors.n_cols;
>   34:    arma::mat simdata(m,n);
>   35:    simdata.row(0) = arma::zeros<arma::mat>(1,n);
>   36:    for (int row=1; row<m; row++) {
>   37:      simdata.row(row) = simdata.row(row-1)*trans(coeff)+errors.row(row);
>   38:    }
>   39:    return Rcpp::wrap(simdata);
>   40:
>   41: END_RCPP
>   42: }
>   43:
>   44:
> Error in compileCode(f, code, language = language, verbose = verbose) :
>    Compilation ERROR, function(s)/method(s) not created!
> Executing command 'C:/PROGRA~1/R/R-214~1.0/bin/i386/R CMD SHLIB file33765791.cpp 2>  file33765791.cpp.err.txt' returned status 1
>
> I am working under R 2.14.0 and as the pros among you might guess, I am new to using the C++ interfaces within R. I think all I have to do is to edit some settings on my Windows 7 machine here, but the error message is too cryptic to me. Alas, I could also not find any thread or help topic that deals with this online. I appreciate any direct reply or reference where I can find a solution to this.
> Please let me know in case I am leaving out some essential details here.

If you put the program source into a file (e.g. fn.cpp) and in a Windows 
cmd shell you run

R CMD SHLIB fn.cpp

what do you get?   I would guess you've got a problem with your setup of 
the compiler or other tools, and this would likely show it.

Duncan Murdoch



[Rd] RcppArmadillo compilation error: R CMD SHLIB returns status 1
Duncan Murdoch