问题描述
尽管互联网上存在一些解决方案,但我发现这些解决方案都不适合我当前面临的问题(尽管也许我只是太笨了):
Although a few solutions exist on the internet, I found none of those suitable for the problem I'm curerntly facing (though maybe I'm simply too dumb):
我正在尝试构建一个R包,该包广泛使用Makefile编译的共享对象(是的,我知道这是一种不好的做法,但是不能告诉Makevars文件将C和Fortran代码编译为一个共享对象)来自程序包src
目录中的代码.无论我在哪里将.so编译到(我尝试过src
,libs
和程序包基本文件夹)或如何命名(如上述解决方案之一所述,都必须像其所包含的程序包一样进行命名) ,R CMD check
以
I'm trying to build an R package which makes extensive use of a shared object compiled by a Makefile (yes, bad practice, I know, but a Makevars file just can't be told to compile C and Fortran code into one shared object) from code in the package's src
directory. No matter where I compile that .so to (I tried the src
, libs
and package base folders) or how I name it (as one of the solutions mentioned above states it must be named like the package it's contained in), R CMD check
exits with
** testing if installed package can be loaded
Error in library.dynam(lib, package, package.lib) :
shared object ‘SoMNibEN.R.so’ not found
由于我的NAMESPACE文件中的useDynLib(SoMNibEN.R)
指令(其中SoMNibEN.R
是我的软件包的名称,但它也不能使用原始名称)
due to the useDynLib(SoMNibEN.R)
instruction in my NAMESPACE file (where SoMNibEN.R
is my package's name, but it didn't work with the original name, either)
我的假设是我要么错误地使用了useDynLib()
命令,要么我的Makefile做错了(尽管编译效果很好,并且共享对象在我的项目文件夹中创建-我只是不这样做)不知道它是否已成功复制到软件包安装目录中.
My assumption is that I'm either using that useDynLib()
command wrong or I'm doing something wrong with my Makefile (although the compilation works pretty well and the shared object is created in my project folder - I just don't know whether it gets copied to the package installation directory successfully).
所以,如果有人知道我在这里做错了什么,请告诉我!
So, if anyone knows what I might be doing wrong here, please let me know!
推荐答案
您想要包的名称作为参数,因为这是共享库的名称 >由R构建,例如useDynLib("chron")
.引号是可选的(例如library()
等).
You want the name of the package as the argument, as that is the name of the shared object built by R, eg useDynLib("chron")
. The quotes are optional (as they are for library()
etc).
我还建议不使用Makefile,而只是将C和Fortran文件拖放到src/
目录中. R通常足够聪明,知道该怎么做.如果需要-I
等开关,可以在此处进行设置.
I also recommend not using a Makefile, but simply dropping the C and Fortran files in the src/
directory. R is generally smart enough to know what to. If you need -I
etc switches you can set them there.
最后,使用CRAN.有数百个带有已编译源代码的软件包,其中一些软件包的结构必然与您的问题相似.
Lastly, use CRAN. There are hundreds of packages with compiled sources, and some are bound to be similar in structure to your question.
这篇关于如何在R包命名空间文件中正确使用useDynLib()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!