Skip to content
Prev 5666 / 12125 Next

[R-pkg-devel] R package does not find DLL routine

On Sun, 28 Jun 2020 12:43:53 +0200
Lisa GM <lisainconnecticut at gmail.com> wrote:

            
As mentioned by Dirk Eddelbuettel, this is not the way R packages are
supposed to be built [*], but if you are absolutely positive you cannot
build the DLL from source together with the package or link your
package to externally installed DLL (as done by packages curl, rgdal,
and many others), it still seems to be possible. I have been able to
get a dummy package to work like this:

.onLoad <- function(libname, pkgname)
 library.dynam('dynl', pkgname, libname, TRUE)

.onUnload <- function(libpath)
 library.dynam.unload('dynl', libpath)

do <- function()
 .C('do_hello', x = as.integer(1L), y = as.numeric(2), PACKAGE = 'dynl')

(Note the extra PACKAGE argument required in absence of native routine
registration or useDynLib(...) declarations in NAMESPACE)

I placed the DLL itself in file.path('inst', 'libs',
paste0('dynl', .Platform$dynlib.ext)) under the package source
directory and made sure that it exports a C function
void do_hello(int * x, double * y).

Needless to say, this goes against CRAN and Bioconductor policies. The
preferred approach is described in Writing R Extensions, section 1.2.