[Rcpp-devel] error: wrap is not a template function

Fabio Tordini tordini at di.unito.it
Thu May 21 17:17:38 CEST 2015


Hello,

while extending Rcpp with my C++ classes, I received hundreds of " 
'wrap' is not a template function" and " 'as' is not a template 
function" errors when compiling. Beside this, I get an impressive list 
of errors referring to RcppGSL files.

The library from which my classes come from makes use GSL (on C++ side), 
thus I link RcppGSL to my package.

Here is my extending for one class:
#ifndef SAMDATA_HPP_
#define SAMDATA_HPP_

class SamData;

#include <RcppCommon.h>

namespace Rcpp {
     template<> SEXP wrap(const SamData &s);
     template<> SamData as( SEXP s ) ;
}

#include <Rcpp.h>

#include "common.hpp"

class SamData {

     // class implementation
};

namespace Rcpp {

template<> SEXP wrap(const SamData &s) {
    return Rcpp::List::create( Rcpp::Named("Chr1") = s.getChr1(),
                               Rcpp::Named("Chr2") = s.getChr2(),
                               Rcpp::Named("Seq1") = s.getSeq(),
                               Rcpp::Named("HS1")  = s.getHS1(),
                               Rcpp::Named("HS2")  = s.getHS2(),
                               Rcpp::Named("Id")   = s.getId(),
                               Rcpp::Named("Start1") = s.getStart1(),
                               Rcpp::Named("Start2") = s.getStart2() );
}

template <> SamData as( SEXP s ) {
     Rcpp::List samL(s);
     SamData sam;
     sam.setChr1( Rcpp::as<std::string>(samL["Chr1"]) );
     sam.setChr2( Rcpp::as<std::string>(samL["Chr2"]) );
     sam.setSeq( Rcpp::as<std::string>(samL["Seq1"]) );
     sam.setHS1( Rcpp::as<size_t>(samL["HS1"]) );
     sam.setHS2( Rcpp::as<size_t>(samL["HS2"]) );
     sam.setStart1( Rcpp::as<long>( samL["Start1"]) );
     sam.setStart2( Rcpp::as<long>( samL["Start2"]) );
     sam.setId( Rcpp::as<long>( samL["Id"]) );

     return sam;
}

}
#endif /* SAMDATA_HPP_ */


The Rcpp package worked just fine before I started using wrap and as. 
Also, this very same code runs fine on a separate sample Rcpp project, 
where I omit the GSL (and RcppGSL) dependency (I could attach it but I 
don't know if it is allowed).

Sorry if this question might sound silly (and it does to me), but is 
there any known issue or incompatibility with RcppGSL and wrap/as?


Thanks,
Fabio




More information about the Rcpp-devel mailing list