[R] linking .lib and/or .dll files
Prof Brian D Ripley
ripley at stats.ox.ac.uk
Thu Jul 1 13:14:44 CEST 2004
On Thu, 1 Jul 2004, Samuel Kemp wrote:
> Linking C++ dynamic libraries has become the bane of my R life. I have a
> piece of C++ code that I would like to make into a .dll (to call into R).
> However, this piece of C++ code needs to be linked with a .dll or .lib -
> which I have been created in Visual C++. Is it possible to link this for use
> in R?
Yes with .lib, if it is a recent VC++. You need to make a mingw import
library, and you can use a tool called reimp to convert a VC++6.0 .lib (but
not earlier).
Alternatively, a tool called pexports can be used to create an exports file
and dlltool can be used to make an import library from that.
Finally, it is supposedly possible to link against a .dll, but I have found
that to be really buggy.
> If so, how do I go about doing this is MINGW?
Create an import library and link against it, and make sure the dlls are in
your path.
CAVEAT: if the C++ code you are calling contains name-mangled symbols you
will be in trouble as VC++ name-mangles in a unique way. In that case you
need to write a piece of C++ glue code that you can compile in VC++ and
that has C entry points that you can call from R.
--
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
More information about the R-help
mailing list