Rev 33359 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
Writing packages for R======================See the Writing R Extensions manual for a full description of howto write a package.Building from a source-code library under Windows=================================================Instructions for installing the toolset and building packages using thestandard methods are in the `R Installation and Administration' manual(which is available in various formats as R-admin.* in the doc/manualdirectory).This file contains instructions for non-standard situations:- Using Microsoft Visual C++- Using Borland C++- Using other compilers and languages- Cross-building packages on LinuxUsing Visual C++================You may if you prefer use Visual C++ to make the DLLs (unless they useFortran source!). First build the import library Rdll.lib bylib /def:R.exp /out:Rdll.libThen you can compile the objects and build the DLL bycl /MT /Ox /D "WIN32" /c *.clink /dll /def:mypkg.def /out:mypkg.dll *.obj Rdll.libwhere you will need to create the .def file by hand listing the entrypoints to be exported. (If there are just a few you can use /exportflags instead.) If the C sources use R header files you will need toarrange for these to be searched, perhaps by including in the cl line/I ..\..\..\includeIf you build a debug version of the DLL in the developmentenvironment, you can debug the DLL code there just by setting theexecutable to be debugged as the full path to the R front-end.Extra care is needed when referencing variables (rather thanfunctions) exported from R.dll. These must be declared__declspec(dllimport) (as in R's own header files). The list of therelevant variables is at the end of the file 'R.exp'.VC++ lacks some standard functions such as isnan and isfinite. To useR's macros you will need#undef ISNAN#define ISNAN(x) _isnan(x)#undef R_FINITE#define R_FINITE(x) _finite(x)for example. Even then, we have seen examples of IEC60559 arithmeticbeing performed incorrectly.Using Borland C++=================Borland C++5.5 is available as a free download fromhttp://www.borland.com/bcppbuilder/freecompiler/ and as part of C++Builder 5. The following will make convolve.dll from convolve.c (flag-6 optimizes for a Pentium Pro/II/III/4, and -u- removes extra underscores)bcc32 -u- -6 -O2 -WDE convolve.cYou can build an import library for R.dll by copying R.exp to R.def andusingimplib R.lib R.defand then add R.lib to the bcc32 command line, for example (fromVenables & Ripley's `S Programming')bcc32 -u- -6 -O2 -WDE -I\R\rw1050\src\include VCrndR.c R.libWe believe that when referencing variables (rather than functions)exported from R.dll these must be declared __declspec(dllimport) justas for VC++.Using other compilers and languages===================================To use C++ see the section in the R for Windows FAQ. You can includeC++ code in packages and the supplied Makefiles will compile with g++and link the DLL using g++ (and hence link against libstc++.a). Useof C++ I/O may or may not work, and has been seen to crash R.For other compilers you will need to arrange to produce a DLL withcdecl (also known as _cdecl or __cdecl) linkage. The mingw port (andVC++) uses no `name mangling' at all, so that if for example yourcompiler adds leading or trailing underscores you will need to use thetransformed symbol in the call to .C in your R code. Many compilerscan produce cdecl DLLs by a suitable choice of flags, but if yourscannot you may need to write some `glue' code in C to interface to theDLL.If you use .Fortran this appends an underscore and does no caseconversion at all to the symbol name. It is normally best to use.C with compilers other than g77 and map the name manually if necessary.Care is needed in passing character strings to and from a DLL by .C:they must be equivalent to the C type char** and null-terminated. Noteven the mingw g77 Fortran uses null-terminated strings.WARNING: DLLs made with some compilers reset the FPU in their startupcode (Delphi has been one), and this will cause operations such as0./0. to crash R. You can re-set the FPU to the correct values by acall to the C entry point Rwin_fpset().For some further details and Delphi examples seehttp://www.stats.uwo.ca/faculty/murdoch/software/compilingDLLs/Cross-building packages on Linux================================It is straightforward to build a package on a ix86-linux system,although it is not possible (and we have tried, including using WINE)to cross-build .chm files. You will need an installation of R forWindows, either copied from a Windows system or cross-compiled.First you need to set up the cross-compilers and tools (see filesrc/gnuwin32/INSTALL in the full source distribution) and have themin your path. We will assume that your Linux installation has Perl5,unzip and zip.Edit MkRules to set BUILD=CROSS and the appropriate paths (includingHEADER) as needed.Then packages can be made as natively, for example bycd .../src/gnuwin32make PKGDIR=/mysources RLIB=/R/win/library pkg-mypkgmake PKGDIR=/mysources RLIB=/R/win/library pkgcheck-mypkgcd /R/win/libraryzip -r9X /dest/mypkg.zip mypkg(Rcmd is a Windows executable, so cannot be used.)Feedback========Please send comments and bug reports toR-windows@r-project.org