使用C代码构建R包,缺少dll [英] Building R package with C code, dll missing

查看:52
本文介绍了使用C代码构建R包,缺少dll的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试构建一个R包,该包通过.Call调用一些C子例程.

I'm trying to build an R package which is calling some C subroutines via .Call.

如果我手动执行R CMD SHLIB然后dyn.load .dll文件,则所有功能都可以正常工作.

All of the functions are working fine if I manually do R CMD SHLIB and then dyn.load the .dll files.

现在,我正在使用R CMD构建来构建软件包.

Now, I'm building the package with R CMD build.

我将所有C代码以及要添加的某些库的.h文件放在src文件夹中.当我运行R CMD版本NAMEPACKAGE时,一切似乎都很好,但是当我运行R CMD检查NAMEPACKAGE时,出现以下错误:

I put all the C code in the src folder, together with the .h files for some libraries I'm adding. When I run R CMD build NAMEPACKAGE everything seems to be fine, but then when I run R CMD check NAMEPACKAGE I get the following errors:

*** arch - i386
Error in library.dynam(lib, package, package.lib) : 
  DLL 'NAMEFUNC' not found: maybe not installed for this architecture?
Error: loading failed
Execution halted
*** arch - x64
Error in library.dynam(lib, package, package.lib) : 
  DLL 'NAMEFUNC' not found: maybe not installed for this architecture?
Error: loading failed
Execution halted
ERROR: loading failed for 'i386', 'x64'

我试图在Internet上获取一些信息,我感觉应该写一个Makevars文件,但是老实说我花了很多时间在Writing R扩展教程(1.2.1)上,我确实努力去理解我到底需要做什么.可以请有人向我解释如何解决该问题吗?考虑一下,我想将我的包裹提交给CRAN.谢谢.

I was trying to get some information on the internet, I have the feeling that I should write a Makevars file, but honestly I spent a lot of time on the Writing R extensions tutorial (1.2.1) and I'm really struggling to understand what is it exactly that I need to do. Could someone please beifly explain to me how to solve the problem? Consider I would like to submit my package to CRAN. Thanks.

推荐答案

我刚刚发现问题出在哪里!(通常)这是一件很愚蠢的事情,我不知道即使您使用特定名称调用某个函数,关联的dll也会自动以程序包的名称而不是函数本身的名称来调用,就像它一样相反,当您只是通过R CMD SHLIB创建dll时,就会发生这种情况.因此,在NAMESPACE中,我必须添加useDynLib(NAMEOFPACKAGE)而不是useDynLib(NAMEOFFUNCTION).

I just found out what the problem was! It was (as usual) a fairly silly thing, I didn't know that even if you call a certain function with a certain name, the associated dll is automatically called with the name of the package and not of the function itself, like it happens instead when you just create your dll through R CMD SHLIB. Therefore, in the NAMESPACE I had to add useDynLib(NAMEOFPACKAGE) instead of useDynLib(NAMEOFFUNCTION).

这篇关于使用C代码构建R包,缺少dll的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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