[R] dyn.load() and dyn.unload() under Windows

Richards, Tom richards at pci.upmc.edu
Tue Feb 20 16:13:37 CET 2001


Hello:

	I am having some difficulty with a DLL, using

> version
         _              
platform i386-pc-mingw32
arch     x86            
os       Win32          
system   x86, Win32     
status                  
major    1              
minor    2.1            
year     2001           
month    01             
day      15             
language R              

I have a library called "weaklink" that I am making, which has exactly one
dll called weaklink.dll, in directory D:\Rw1021\library\weaklink\libs.  I
have used mingw32/gcc 2.95.2-1 to make the dll, with these commands I got
from Professor Ripley a couple weeks ago (thanks for that, and any errors
are due to me!):

gcc -O2 -c weaklink.c -ID:\Rw1021\src\include
dlltool --export-all-symbols --output-def weaklink.def weaklink.o
gcc --shared -o ..\libs\weaklink.dll weaklink.def weaklink.o
-LD:/Rw1021/src/gnuwin32 -lR

The file weaklink.def made by mingw32 looks like this:

; dlltool --export-all-symbols --output-def weaklink.def weaklink.o
EXPORTS
	sann @ 1 ; 
	combn2 @ 2 ; 

In the file D:\Rw1021\library\weaklink\R\weaklink, I have this function:

.First.lib <- function(lib, pkg) {
	library.dynam("weaklink", pkg, lib)
	require(MASS)
}

In weaklink.c, there are two functions declared, as

__declspec (dllexport) SEXP sann(SEXP input);
__declspec (dllexport) SEXP combn2(SEXP input);

Shouldn't BOTH exported symbols exported be loaded into R?  Well, here is
what I get:

> library(weaklink)
Loading required package: MASS 

> is.loaded(symbol.C("sann"))
[1] TRUE
> is.loaded(symbol.C("combn2"))
[1] FALSE

and even if I use dyn.load(), I do not get what I want:

> dyn.load("D:\\Rw1021\\library\\weaklink\\libs\\weaklink.dll")
> is.loaded(symbol.C("sann"))
[1] TRUE
> is.loaded(symbol.C("combn2"))
[1] FALSE

I think that the arguments "symbol" and "name" to dyn.load(), on page 146 of
refman.pdf, have been deprecated, since they're not really there:

> args(dyn.load)
function (x, local = TRUE, now = TRUE) 
NULL

I must be missing something here, because MASS only has one dll file, and it
must have many exported symbols.  Can anyone tell me what I'm doing wrong
here?  Thanks in advnace for your help.

Tom


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list