[R] Link with C code

Prof Brian Ripley ripley at stats.ox.ac.uk
Tue Jan 30 17:38:51 CET 2001


On Tue, 30 Jan 2001, Richards, Tom wrote:

> Hello:
>
> 	I need to ask a small question about the *recommended* compiler for
> Windows, mingw32 gcc 2.95.2.

Actually, it is gcc 2.95.2-1, and the -1 is important.

> Suppose that I have a file called doit.c, and
> a file doit.def which specifies that the function foo() be exported. I need
> to link against Rdll.lib, to make doit.dll, which I want to load into R
> 1.2.1.  What are the correct mingw32 commands to do this?  After playing
> with gcc, dlltools, dllwrap, and S Programming for some time, all I have
> come up with is
>
> gcc -O2 -c doit.c -ID:\Rw1021\src\include
> dlltool -e doit.exp -l doit.lib --export-all-symbols doit.o
> gcc doit.o doit.exp D:\Rw1021\bin\Rdll.lib -o doit.dll

(Don't know where you got that last line from, but not S Programming for
sure.)

> The first line works perfectly, thanks to Sprog, but I cannot get the
> compiler to find Rdll.lib.  Every time I run the script above, I get the
> same mesage that VC++ 6.0 gives when I fail to link against Rdll.lib.  Can
> anyone help?  thanks in advance.

You link against libR.a, not Rdll.lib.  The makefiles will do all this for
you, but you could just run (once) in src/gnuwin32

dlltool --dllname R.dll --def R.exp --output-lib libR.a

Then

gcc -O2 -c doit.c -ID:\Rw1021\src\include
<see below>
gcc --shared -o doit.dll doit.def doit.o -LD:/Rw1021/src/gnuwin32 -lR

You need to create doit.def.  The Makefiles use nm and sed, but

dlltool --export-all-symbols --output-def doit.def doit.o

should do it.

It really is easiest just to let the Makefiles take the strain or
exactly follow a proven recipe.

>
> Tom Richards
>
>
>
> > -----Original Message-----
> > From: Patrick Wendel [mailto:p.wendel at ic.ac.uk]
> > Sent: Tuesday, January 30, 2001 8:05 AM
> > To: r-help at stat.math.ethz.ch
> > Subject: [R] Link with C code
> >
> >
> >
> >
> > Hello,
> >
> > I am using cygwin (latest version) and I managed to generate
> > a dll partly
> > with rcmd shlib although there was a problem with both the
> > resouce file (I
> > had to remove "FILEOS VOS__WINDOWS32") and the command line for gcc
> > (--shared is not supported for instance).
> >
> > So I would like to know which compiler/environment you advise
> > to use for
> > windows OS.
> >
> > Then I could load the library in R but couldn't call any method.
> >
> > Is there a function to know which functions have been
> > successfully imported
> > ?
> >
> > I've also done the dll in other ways (using gcc and dlltool
> > as explained on
> > their website and also using VC++) but I had the same result.
> >
> > I suppose I missed something in the dll creation but I cannot
> > see what.
> >
> > Any idea ?
> >
> > Many thanks,
> >
> > Patrick Wendel
> >
> > -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
> > -.-.-.-.-.-.-.-.-
> > 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
> > _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._.
> > _._._._._._._._._
> >
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> 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
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
>

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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