如何在R包之间共享基于Rcpp的库中的C ++函数? [英] How do I share C++ functions in Rcpp-based libraries between R packages?

查看:249
本文介绍了如何在R包之间共享基于Rcpp的库中的C ++函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Rcpp中开发一个简单的库来构建Huffman树。它有一个工作的R接口我可以从其他包调用,但我也想调用C ++函数直接从C ++代码在其他基于Rcpp的包我正在开发。



我已经弄清楚如何将第一个包的头放在 inst / include 目录中,以便它在第二个包中可用。但是,当在第二个包的 NAMESPACE 文件中调用 useDynLib 时,加载它的C ++代码,包,我得到一个未定义的符号错误的功能,我想使用。我有第二个包中 DESCRIPTION 文件中列出的第一个包导入 code>和 LinkingTo



这是我第一次进行任何非R基础包,我通过Rstudio的Build& Reload命令做所有我的开发,并在我创建包以生成初始目录结构时使用w / Rcpp包选项。



查看例如:

在RcppXts包如何导入xts包导出的符号。这是非常乏味的。



我想Kevin在他的Kmisc包中需要一些帮助。我一直在读这些,但不需要他们/有时间了。


I'm developing a simple library in Rcpp that builds Huffman trees. It has a working R interface I can call from other packages, but I'd also like to call the C++ functions directly from C++ code in other Rcpp-based packages I'm developing.

I've figured out how to put the header for the first package in the inst/include directory so that it is available in the second package. However, when useDynLib is called in the second package's NAMESPACE file to load it's C++ code that calls a function in the first package, I get an undefined symbol error for the function I am trying to use. I have the first package listed in the second package's DESCRIPTION file under Import, Depends, and LinkingTo.

This is my first foray into doing any non-R based packages, and I'm doing all my development via Rstudio's "Build & Reload" command and used the "Package w/ Rcpp" option when I created the packages to generate the initial directory structure.

解决方案

Yes, the linking step is harder but still doable.

Look e.g. at how the RcppXts package imports symbols which the xts package exports. This is all pretty tedious.

I think Kevin has some helpers for the required registration step in his Kmisc package. I have been meaning to read up on those but have not needed them / had time yet.

这篇关于如何在R包之间共享基于Rcpp的库中的C ++函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆