Skip to content

compileAttributes registers wrong name for exported functions #709

@mlysy

Description

@mlysy

Hello,

The current version of compileAttributes generates an error when Rcpp::exports provides a different R name for the C++ function. Interestingly, the error only occurs for packages, not when code is compiled on-the-fly with sourceCpp. Sample code below:

sessionInfo:

R version 3.4.0 (2017-04-21)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Sierra 10.12.4

Matrix products: default
BLAS: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRblas.0.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRlapack.dylib

locale:
[1] en_CA.UTF-8/en_CA.UTF-8/en_CA.UTF-8/C/en_CA.UTF-8/en_CA.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] Rcpp_0.12.11

loaded via a namespace (and not attached):
[1] compiler_3.4.0  tools_3.4.0     pkgKitten_0.1.4

Code:

require(Rcpp)

code <- "
#include <Rcpp.h>
//[[Rcpp::export(\"foo\")]]
double bar(double x, double y) {return x+y;}
"

# this works fine
sourceCpp(code = code)
foo(3.5, 2.6)

# this does not
Rcpp.package.skeleton(name = "RcppExportTest", example_code = FALSE)
cat(code, file = file.path("RcppExportTest", "src", "test.cpp"))
compileAttributes("RcppExportTest")

Upon compiling I get the error message:

RcppExports.cpp:22:39: error: use of undeclared identifier 'RcppExportTest_foo';
      did you mean 'RcppExportTest_bar'?
    {"RcppExportTest_foo", (DL_FUNC) &RcppExportTest_foo, 2},
                                      ^~~~~~~~~~~~~~~~~~
                                      RcppExportTest_bar
RcppExports.cpp:10:17: note: 'RcppExportTest_bar' declared here
RcppExport SEXP RcppExportTest_bar(SEXP xSEXP, SEXP ySEXP) {
                ^
1 error generated.

The problem seems to be that RcppExports.cpp attempts to register the R name of the exported function rather than the C++ name. Indeed, replacing the RcppExports.cpp lines

static const R_CallMethodDef CallEntries[] = {
    {"RcppExportTest_foo", (DL_FUNC) &RcppExportTest_foo, 2},
    {NULL, NULL, 0}
};

by

static const R_CallMethodDef CallEntries[] = {
    {"RcppExportTest_bar", (DL_FUNC) &RcppExportTest_bar, 2},
    {NULL, NULL, 0}
};

fixes the problem.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions