Rcpp wrapper for the .C interface

徘徊边缘 提交于 2019-12-24 12:21:53

问题


I help to maintain the R package iRF. As you can see, it have been using Rcpp to call some C functions via the .C interface since its last release in 2017.

When I clone that repo and try to install it on my computer (running macOS Mojave) with the latest version of R and Rcpp, it installs successfully. However, any modification to the src/ directory would change some MD5 hash and trigger an Rcpp::compileAttributes. Unfortunately, the recompiled attributes don't work with the legacy .C interface.

/tmp/iRF master#2.0.0
$ Rscript -e 'Rcpp::compileAttributes()'

/tmp/iRF master#2.0.0
$ R CMD INSTALL .
* installing to library ‘/usr/local/lib/R/3.6/site-library’
* installing *source* package ‘iRF’ ...
files ‘R/RcppExports.R’, ‘src/RcppExports.cpp’ have the wrong MD5 checksums
** using staged installation
** libs
clang++ -std=gnu++11 -I"/usr/local/Cellar/r/3.6.1/lib/R/include" -DNDEBUG  -I"/usr/local/lib/R/3.6/site-library/Rcpp/include" -I/usr/local/opt/gettext/include -I/usr/local/opt/llvm/include  -fPIC  -g -O2  -c ExportedFunctionsRIT.cpp -o ExportedFunctionsRIT.o
clang++ -std=gnu++11 -I"/usr/local/Cellar/r/3.6.1/lib/R/include" -DNDEBUG  -I"/usr/local/lib/R/3.6/site-library/Rcpp/include" -I/usr/local/opt/gettext/include -I/usr/local/opt/llvm/include  -fPIC  -g -O2  -c RcppExports.cpp -o RcppExports.o
/usr/local/opt/llvm/bin/clang -fopenmp -I"/usr/local/Cellar/r/3.6.1/lib/R/include" -DNDEBUG  -I"/usr/local/lib/R/3.6/site-library/Rcpp/include" -I/usr/local/opt/gettext/include -I/usr/local/opt/llvm/include  -fPIC  -g -O3 -Wall -pedantic -std=gnu99 -mtune=native -pipe -c classTree.c -o classTree.o
/usr/local/opt/llvm/bin/clang -fopenmp -I"/usr/local/Cellar/r/3.6.1/lib/R/include" -DNDEBUG  -I"/usr/local/lib/R/3.6/site-library/Rcpp/include" -I/usr/local/opt/gettext/include -I/usr/local/opt/llvm/include  -fPIC  -g -O3 -Wall -pedantic -std=gnu99 -mtune=native -pipe -c init.c -o init.o
clang++ -std=gnu++11 -I"/usr/local/Cellar/r/3.6.1/lib/R/include" -DNDEBUG  -I"/usr/local/lib/R/3.6/site-library/Rcpp/include" -I/usr/local/opt/gettext/include -I/usr/local/opt/llvm/include  -fPIC  -g -O2  -c processNodes.cpp -o processNodes.o
/usr/local/opt/llvm/bin/clang -fopenmp -I"/usr/local/Cellar/r/3.6.1/lib/R/include" -DNDEBUG  -I"/usr/local/lib/R/3.6/site-library/Rcpp/include" -I/usr/local/opt/gettext/include -I/usr/local/opt/llvm/include  -fPIC  -g -O3 -Wall -pedantic -std=gnu99 -mtune=native -pipe -c regTree.c -o regTree.o
regTree.c:209:9: warning: unused variable 'jj' [-Wunused-variable]
    int jj, jold;
        ^
regTree.c:416:14: warning: unused variable 'dum' [-Wunused-variable]
        int i, tmp, dum;
                    ^
2 warnings generated.
/usr/local/opt/llvm/bin/clang -fopenmp -I"/usr/local/Cellar/r/3.6.1/lib/R/include" -DNDEBUG  -I"/usr/local/lib/R/3.6/site-library/Rcpp/include" -I/usr/local/opt/gettext/include -I/usr/local/opt/llvm/include  -fPIC  -g -O3 -Wall -pedantic -std=gnu99 -mtune=native -pipe -c regrf.c -o regrf.o
/usr/local/opt/llvm/bin/clang -fopenmp -I"/usr/local/Cellar/r/3.6.1/lib/R/include" -DNDEBUG  -I"/usr/local/lib/R/3.6/site-library/Rcpp/include" -I/usr/local/opt/gettext/include -I/usr/local/opt/llvm/include  -fPIC  -g -O3 -Wall -pedantic -std=gnu99 -mtune=native -pipe -c rf.c -o rf.o
rf.c:492:17: warning: expression result unused [-Wunused-value]
  ...+                                                          nrightimp[cl[n] - 1]++;
     ^                                                               ~~~~~~~~~~~~~~~~~~~~~~
1 warning generated.
gfortran -fno-optimize-sibling-calls  -fPIC  -g -O2  -c rfsub.f -o rfsub.o
/usr/local/opt/llvm/bin/clang -fopenmp -I"/usr/local/Cellar/r/3.6.1/lib/R/include" -DNDEBUG  -I"/usr/local/lib/R/3.6/site-library/Rcpp/include" -I/usr/local/opt/gettext/include -I/usr/local/opt/llvm/include  -fPIC  -g -O3 -Wall -pedantic -std=gnu99 -mtune=native -pipe -c rfutils.c -o rfutils.o
clang++ -std=gnu++11 -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/usr/local/opt/gettext/lib -L/usr/local/opt/llvm/lib -Wl,-rpath,/usr/local/opt/llvm/lib -L/usr/local/Cellar/r/3.6.1/lib/R/lib -L/usr/local/opt/gettext/lib -L/usr/local/opt/llvm/lib -Wl,-rpath,/usr/local/opt/llvm/lib -o iRF.so ExportedFunctionsRIT.o RcppExports.o classTree.o init.o processNodes.o regTree.o regrf.o rf.o rfsub.o rfutils.o -L/usr/local/opt/gcc/lib/gcc/9/gcc/x86_64-apple-darwin18/9.1.0 -L/usr/local/opt/gcc/lib/gcc/9 -lgfortran -lquadmath -lm -L/usr/local/Cellar/r/3.6.1/lib/R/lib -lR -lintl -Wl,-framework -Wl,CoreFoundation
installing to /usr/local/lib/R/3.6/site-library/00LOCK-iRF/00new/iRF/libs
** R
** data
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded from temporary location
Error: package or namespace load failed for ‘iRF’ in dyn.load(file, DLLpath = DLLpath, ...):
 unable to load shared object '/usr/local/lib/R/3.6/site-library/00LOCK-iRF/00new/iRF/libs/iRF.so':
  dlopen(/usr/local/lib/R/3.6/site-library/00LOCK-iRF/00new/iRF/libs/iRF.so, 6): Symbol not found: _iRF_RIT_1class
  Referenced from: /usr/local/lib/R/3.6/site-library/00LOCK-iRF/00new/iRF/libs/iRF.so
  Expected in: flat namespace
 in /usr/local/lib/R/3.6/site-library/00LOCK-iRF/00new/iRF/libs/iRF.so
Error: loading failed
Execution halted
ERROR: loading failed
* removing ‘/usr/local/lib/R/3.6/site-library/iRF’
* restoring previous ‘/usr/local/lib/R/3.6/site-library/iRF’

It seems that Rcpp in 2019 has dropped the .C interface and supports .Call exclusively, but asking users to install ancient R and Rcpp versions isn't really practical. I understand that the best solution is probably rewriting the R and C code to use .Call, but the functions take tens of arguments and span hundreds of lines, so that is going to be tedious.

How can I get around with this issue?

来源:https://stackoverflow.com/questions/57366463/rcpp-wrapper-for-the-c-interface

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!