gpt4 book ai didi

r - 当包名包含 "dot"和 Rcpp 函数时,包编译失败

转载 作者:行者123 更新时间:2023-12-04 15:22:59 25 4
gpt4 key购买 nike

我正在构建一个新包:

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

  • 当我使用 Rcmd INSTALL 构建包时, compileAttributes用于幕后自动生成导出函数,
    RcppExport SEXP my.package_rcppfunction(...)

    由于导出名称中的点,我收到编译错误:
    RcppExports.cpp:10:19: error: expected initializer before '.' token

    作为一种解决方法,我可以更改包名称以从中删除点,但我想要更好的解决方案并了解符号的导出方式。所以我的问题是:
  • 例如,我如何参数化生成的代码以用“_”替换点(也许通过为导出属性提供一些参数)。
  • 或如何更改 g++ 调用以强制它编译此类带点符号..

  • 我不知道这是否有帮助,但这里是我的 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

    最佳答案

    你不能这样做——在 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 .

    关于r - 当包名包含 "dot"和 Rcpp 函数时,包编译失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20720796/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com