错误:对于包X的.call(),函数不可用

编程入门 行业动态 更新时间:2024-10-24 11:12:32
本文介绍了错误:对于包X的.call(),函数不可用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我刚刚开始试验RCPP包,所以请耐心等待。

我阅读了RCPP小品,并尝试了RCPP文档中的几个给定示例。现在,我想我应该从包装GLFWLibray中的一些函数开始,这是一个用C编写的库

所以我想我应该从函数glfwInit开始。我在一个名为Pixel的包中编写了这个简单的CPP源文件,将其包装为glfw_init:

#include <Rcpp.h> #include <GLFW/glfw3.h> using namespace Rcpp; //' @export // [[Rcpp::export]] int glfw_init() { return(glfwInit()); }

我在RStudio中工作,使用生成文档和构建包的常见清洗和重复循环(我使用的是roxygen2)。

该函数被导出到R和用户空间,所以如果我在R控制台中键入glfw_init,我会得到:

function() { .Call('_pixel_glfw_init', PACKAGE = 'pixel') } <bytecode: 0x5558ece6f398> <environment: namespace:pixel>

但如果我尝试使用glfw_init()运行它,却收到错误:

Error in .Call("_pixel_glfw_init", PACKAGE = "pixel") : "_pixel_glfw_init" not available for .Call() for package "pixel"

我觉得我遗漏了一些次要的设置细节才能正常工作...如有任何帮助,我们将不胜感激!

附言:根据Konrad的评论,我在这里发布了我在RStudio的构建面板中获得的输出:

==> Rcpp::compileAttributes() * Updated R/RcppExports.R ==> R CMD INSTALL --no-multiarch --with-keep.source pixel g++ -std=gnu++11 -I"/usr/include/R/" -DNDEBUG -I"/home/rmagno/R/x86_64-pc-linux-gnu-library/3.6/Rcpp/include" -D_FORTIFY_SOURCE=2 -fpic -march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong -fno-plt -c glfw.cpp -o glfw.o * installing to library ‘/home/rmagno/R/x86_64-pc-linux-gnu-library/3.6’ * installing *source* package ‘pixel’ ... ** using staged installation ** libs g++ -std=gnu++11 -shared -L/usr/lib64/R/lib -Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now -o pixel.so RcppExports.o glfw.o -L/usr/lib64/R/lib -lR installing to /home/rmagno/R/x86_64-pc-linux-gnu-library/3.6/00LOCK-pixel/00new/pixel/libs ** R ** 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 ** checking absolute paths in shared objects and dynamic libraries ** testing if installed package can be loaded from final location ** testing if installed package keeps a record of temporary installation path * DONE (pixel)

P.S.2:以下是我的命名空间:

# Generated by roxygen2: do not edit by hand export(coords_rectangle) export(coords_rectangular_lattice) export(coords_segment) export(coords_square) export(display_matrix_int) export(glfw_init) export(lgl_matrix_to_coords_grid_segment) export(lgl_matrix_to_coords_segment) export(palette_for_quads)

P.S.3:新建文件后R/pixel.R:

#' @useDynLib pixel, .registration = TRUE #' @importFrom Rcpp sourceCpp NULL

我现在尝试生成文档时收到此错误:

==> Rcpp::compileAttributes() * Updated R/RcppExports.R ==> devtools::document(roclets = c('rd', 'collate', 'namespace')) Updating pixel documentation Loading pixel Error in dyn.load(dllfile) : unable to load shared object '/home/rmagno/sci/code/R/pkg/pixel/src/pixel.so': /home/rmagno/sci/code/R/pkg/pixel/src/pixel.so: undefined symbol: glfwInit Calls: suppressPackageStartupMessages ... <Anonymous> -> load_dll -> library.dynam2 -> dyn.load Execution halted Exited with status 1. 推荐答案

新错误指示您没有将C++代码链接到GLFW库。您需要提供将库添加到PKG_LIBS的src/Makevars文件。请参阅编写R扩展手册中的Using Makevars。

更多推荐

错误:对于包X的.call(),函数不可用

本文发布于:2023-06-13 00:00:38,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/670292.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不可用   函数   错误   call

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!