当包名称包含“点”和Rcpp函数时,包编译失败

时间:2013-12-21 15:57:52

标签: r g++ rcpp

我正在构建一个新包:

  • 包名称包含一个点:例如 my.package
  • 包导出一个Rcpp函数:例如 rcppfunction

当我使用Rcmd INSTALL构建包时,在场景后面使用compileAttributes来自动生成导出的函数,

RcppExport SEXP my.package_rcppfunction(...)

由于导出名称中的点而导致编译错误:

RcppExports.cpp:10:19: error: expected initializer before '.' token

作为一种解决方法,我可以更改包名称以从中删除点,但我想要更好的解决方案并了解符号的导出方式。所以我的问题是:

  1. 如何将生成的代码参数化为例如用“_”替换点(也许通过为export属性提供一些参数)。
  2. 或者如何更改g ++调用以强制它编译这样的虚线符号..
  3. 我不知道这是否有帮助,但这里是我的g ++电话:

    g++ -m32 -I"PATH_TO_R/R-30~1.2/include" -DNDEBUG    -
    I"PATH_To_R/3.0/Rcpp/include" -
    I"d:/RCompile/CRANpkg/extralibs64/local/include"     
    -O2 -Wall  -mtune=core2 -c RcppExports.cpp -o RcppExports.o
    

1 个答案:

答案 0 :(得分:4)

你不能这样做 - 在C或C ++函数名中不允许使用点:

#include <stdlib.h>

int foo.bar(int x) {
    return(2*x);
}

int main(void) {
    foo.bar(21);
    exit(0);
}

我们得到了

edd@max:/tmp$ gcc -c foo.c
foo.c:4: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘.’ token
foo.c: In function ‘main’:
foo.c:9: error: ‘foo’ undeclared (first use in this function)
foo.c:9: error: (Each undeclared identifier is reported only once
foo.c:9: error: for each function it appears in.)
edd@max:/tmp$ 

edd@max:/tmp$ g++ -c foo.c
foo.c:4: error: expected initializer before ‘.’ token
foo.c: In function ‘int main()’:
foo.c:9: error: ‘foo’ was not declared in this scope
edd@max:/tmp$ 

在C ++中,foo.bar()正在调用对象bar()的成员函数foo