Re: [R] linking .lib and/or .dll files

From: Prof Brian D Ripley <ripley_at_stats.ox.ac.uk>
Date: Thu 01 Jul 2004 - 21:14:44 EST


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@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@stat.math.ethz.ch mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Received on Thu Jul 01 21:17:42 2004

This archive was generated by hypermail 2.1.8 : Wed 03 Nov 2004 - 22:54:38 EST