我正在用头撞墙,试图让
Rcpp
在 Raspberry Pi 上构建 SPI 包。
我的代码/包可以在我的 GitHub 上找到:https://github.com/mnr/rpigpior/
当我跑步
Rcpp::compileAttributes()
,然后是load_all()
时,我一直得到
RcppExports.cpp:14:32:错误:'spi_config_t'尚未声明
很明显我还没有声明或链接一些重要的东西 - 但我不清楚我需要在哪里声明链接以及我需要链接什么。
有人有过这样的经历吗?
从位于 https://github.com/mnr/rpigpior/
的包源开始> Rcpp::compileAttributes()
> load_all()
ℹ Loading rpigpior
Exports from /home/pi/Documents/rpigpior/src/rpi_spi_open.cpp:
int rpi_spi_open(char *device, spi_config_t config)
/home/pi/Documents/rpigpior/src/RcppExports.cpp updated.
/home/pi/Documents/rpigpior/R/RcppExports.R updated.
ℹ Re-compiling rpigpior (debug build)
── R CMD INSTALL ───────────────────────────────────────────────────────────────────────────────────────────────────
─ installing *source* package ‘rpigpior’ ... (730ms)
** using staged installation
** libs
using C compiler: ‘gcc (Raspbian 10.2.1-6+rpi1) 10.2.1 20210110’
using C++ compiler: ‘g++ (Raspbian 10.2.1-6+rpi1) 10.2.1 20210110’
g++ -std=gnu++17 -I"/opt/R/release/lib/R/include" -DNDEBUG -I'/home/pi/R/armv7l-unknown-linux-gnueabihf-library/4.3/Rcpp/include' -I/usr/local/include -fPIC -g -O2 -UNDEBUG -Wall -pedantic -g -O0 -fdiagnostics-color=always -c RcppExports.cpp -o RcppExports.o
RcppExports.cpp:14:32: error: ‘spi_config_t’ has not been declared
14 | int rpi_spi_open(char *device, spi_config_t config);
| ^~~~~~~~~~~~
RcppExports.cpp: In function ‘SEXPREC* _rpigpior_rpi_spi_open(SEXPREC**, SEXP)’:
RcppExports.cpp:19:57: error: cannot convert ‘SEXP’ {aka ‘SEXPREC*’} to ‘Rcpp::traits::input_parameter<char>::type*’ {aka ‘Rcpp::InputParameter<char>*’} in initialization
19 | Rcpp::traits::input_parameter< char >::type *device(*deviceSEXP);
| ^~~~~~~~~~~
| |
| SEXP {aka SEXPREC*}
In file included from /home/pi/R/armv7l-unknown-linux-gnueabihf-library/4.3/Rcpp/include/Rcpp/r/headers.h:67,
from /home/pi/R/armv7l-unknown-linux-gnueabihf-library/4.3/Rcpp/include/RcppCommon.h:30,
from /home/pi/R/armv7l-unknown-linux-gnueabihf-library/4.3/Rcpp/include/Rcpp.h:27,
from RcppExports.cpp:4:
/opt/R/release/lib/R/include/Rinternals.h:180:16: note: class type ‘SEXPREC’ is incomplete
180 | typedef struct SEXPREC *SEXP;
| ^~~~~~~
RcppExports.cpp:20:36: error: ‘spi_config_t’ was not declared in this scope
20 | Rcpp::traits::input_parameter< spi_config_t >::type config(configSEXP);
| ^~~~~~~~~~~~
RcppExports.cpp:20:49: error: template argument 1 is invalid
20 | Rcpp::traits::input_parameter< spi_config_t >::type config(configSEXP);
| ^
RcppExports.cpp:20:57: error: expected initializer before ‘config’
20 | Rcpp::traits::input_parameter< spi_config_t >::type config(configSEXP);
| ^~~~~~
RcppExports.cpp:21:56: error: ‘config’ was not declared in this scope
21 | rcpp_result_gen = Rcpp::wrap(rpi_spi_open(*device, config));
| ^~~~~~
make: *** [/opt/R/release/lib/R/etc/Makeconf:200: RcppExports.o] Error 1
ERROR: compilation failed for package ‘rpigpior’
─ removing ‘/tmp/RtmpN8Haun/devtools_install_10981336a33c/rpigpior’
Error in `(function (command = NULL, args = character(), error_on_status = TRUE, …`:
! System command 'R' failed
---
Exit status: 1
stdout & stderr: <printed>
---
查看错误信息:
RcppExports.cpp:14:32: error: ‘spi_config_t’ has not been declared
14 | int rpi_spi_open(char *device, spi_config_t config);
| ^~~~~~~~~~~~
RcppExports.cpp: In function ‘SEXPREC* _rpigpior_rpi_spi_open(SEXPREC**, SEXP)’:
RcppExports.cpp:19:57: error: cannot convert ‘SEXP’ {aka ‘SEXPREC*’} to ‘Rcpp::traits::input_parameter<char>::type*’ {aka ‘Rcpp::InputParameter<char>*’} in initialization
19 | Rcpp::traits::input_parameter< char >::type *device(*deviceSEXP);
我们看到入口点或粘合函数没有使用标准 Rcpp 数据类型和/或为自定义结构定义转换器。
// [[Rcpp::export]]
int rpi_spi_open(char *device, spi_config_t config) {
在这种情况下,尝试为
as
结构定义必要的 wrap()
/spi_config_t
函数,或者直接在 C++ 函数内部初始化它,并允许参数包含支持的类型。
您可以在此处查看创建自定义
wrap()
/as()
的有效示例:
https://gallery.rcpp.org/articles/custom-templated-wrap-and-as-for-seamingless-interfaces/