[Rcpp-devel] Error with NumericMatrix using SourceCpp

Thu Jan 2 23:20:40 CET 2014

Hello everyone,

I’m getting a weird error anytime I try to use a NumericMatrix in a function compiled using the sourceCpp function.  In case it matters, I’m running Mac OS X 10.9.1.

I compiled a simple NumericVector function with no problem:


src <- '
#include <Rcpp.h>
using namespace Rcpp;
// [[Rcpp::export]]
NumericVector fun1()
NumericVector a(3, 10.0);
sourceCpp(code = src)

When I try a similar function with a NumericMatrix, I get an error.  I tried to compile:

src2 <- '
#include <Rcpp.h>
using namespace Rcpp;
// [[Rcpp::export]]
NumericMatrix fun2()
NumericMatrix a(3, 2);
return a;
sourceCpp(code = src2)

And get the following error:

Error in dyn.load("/var/folders/x7/cm9jq3nn6mxdn31r9sw3sbv80000gn/T//RtmpaRBweq/sourcecpp_15e0218ec23e/sourceCpp_38196.so") :
  unable to load shared object '/var/folders/x7/cm9jq3nn6mxdn31r9sw3sbv80000gn/T//RtmpaRBweq/sourcecpp_15e0218ec23e/sourceCpp_38196.so':
  dlopen(/var/folders/x7/cm9jq3nn6mxdn31r9sw3sbv80000gn/T//RtmpaRBweq/sourcecpp_15e0218ec23e/sourceCpp_38196.so, 6): Symbol not found: __ZNK4Rcpp7RObject4attrERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE
  Referenced from: /var/folders/x7/cm9jq3nn6mxdn31r9sw3sbv80000gn/T//RtmpaRBweq/sourcecpp_15e0218ec23e/sourceCpp_38196.so
  Expected in: flat namespace
 in /var/folders/x7/cm9jq3nn6mxdn31r9sw3sbv80000gn/T//RtmpaRBweq/sourcecpp_15e0218ec23e/sourceCpp_38196.so

Thinking perhaps I messed up, I tried to compile a stripped down Gibbs sampler example from Dirk to no avail (http://gallery.rcpp.org/articles/gibbs-sampler/).

src3 <- '
// load Rcpp
#include <Rcpp.h>

using namespace Rcpp; // shorthand

// [[Rcpp::export]]
NumericMatrix RcppGibbs(int n, int thn) {

    int i,j;
    NumericMatrix mat(n, 2);
    return mat;             // Return to R
sourceCpp(code = src3)

What is going on?  If I am missing something very simple, please forgive me.  I’ve been beating my head against the wall for over an hour now looking at examples, trying to create the simplest tests possible, to no avail.



Joshua French, Ph.D.
Assistant Professor
Department of Mathematical and Statistical Sciences
University of Colorado Denver
Joshua.French at ucdenver.edu<mailto:Joshua.French at ucdenver.edu>
Ph:  303-315-1709  Fax:  303-315-1701
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20140102/bad2f584/attachment-0001.html>

More information about the Rcpp-devel mailing list