gpt4 book ai didi

c - 在 R 包中设置动态链接库的目录路径

转载 作者:太空宇宙 更新时间:2023-11-04 02:34:27 25 4
gpt4 key购买 nike

在编写 R 包时加载动态链接库(即 .so 文件)的正确方法是什么?到目前为止,唯一对我有用的解决方案是指定 .so 文件的完整路径,例如:

dyn.load('/FULL/PATH/TO/MY/R_PACKAGE/src/my_file.so')

显然,这种方法不适用于 CRAN/Bioconductor 提交,因为找不到 .so 文件。因此,我(未成功)尝试了以下替代方法:

1) library.dynam()

2) library.dynam('my_file.so')

3) library.dynam('my_file.so', 'R_PACKAGE')

4) system.file("src", "my_file.so", package = "R_PACKAGE")

相关链接:R: C symbol not in load table , R: C symbol name not in load table - error in linking with external .c files .

明确地说,我的 R 包的用户显然可以在他们的计算机上设置任意任意工作目录。完整路径方法(如上所示)唯一可行的方法是将工作目录设置为 /FULL/PATH/TO/MY/R_PACKAGE/src,这(当然)是不切实际的.

最佳答案

执行此操作的标准方法,如 Writing R Extensions 中所述, 是:

1.5.4 useDynLib

A NAMESPACE file can contain one or more useDynLib directives which allows shared objects that need to be loaded.* The directive

useDynLib(foo)

registers the shared object foo** for loading with library.dynam. Loading of registered object(s) occurs after the package code has been loaded and before running the load hook function. Packages that would only need a load hook function to load a shared object can use the useDynLib directive instead.

* NB: this will only be read in all versions of R if the package contains R code in a R directory.** Note that this is the basename of the shared object, and the appropriate extension (.so or .dll) will be added.

关于c - 在 R 包中设置动态链接库的目录路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39354959/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com