Rev 15896 | Blame | Last modification | View Log | Download | RSS feed
Building from a source-code library under Windows=================================================[If you are reading this file as part of the full R source distribution,you need to build R first: see file INSTALL.]If your package has no C nor Fortran nor C++ sources, see `Simple ports'near the bottom of this file.First collect the tools that you need. There is a `portal' withcurrent links at http://www.stats.ox.ac.uk/pub/Rtools/.You will need suitable versions of at least make, sh, cat, cp, diff,echo, mkdir, mv, rm, sed; we have packaged a set athttp://www.stats.ox.ac.uk/pub/Rtools/tools.zip extracted from thecygwin distribution (http://www.cygwin.com/mirrors.html) or (gzip)compiled from the sources.BEWARE: `Native' ports of make are _not_ suitable (including that atthe mingw site). There were also problems with several earlierversions of the cygwin tools and dll. To avoid frustration, pleaseuse our tool set.We recommend that you use a recent snapshot of the mingw port of gccfrom http://downloads.sourceforge.net/mingw/. For example, at thetime of writing, MinGW-1.1.tar.gz based on gcc-2.95.3. Just unpackthis somewhere and put its bin directory in your path.You may also be able to use the mingw port of gcc-2.95.2-1 by MumitKhan linked from http://www.mingw.org/, but you *cannot* use earlierversions of the mingw compilers, for example gcc-2.95.2 (no -1): thesymptom is a report that `-shared' is not understood. [This option isno longer tested, though.]The Windows port of perl5, available viahttp://www.activestate.com/Products/ActivePerl/.If you want to make compiled html (.chm) files you will need theMicrosoft HTML Help Workshop, currently available for download athttp://msdn.microsoft.com/library/en-us/htmlhelp/html/hwMicrosoftHTMLHelpDownloads.aspand http://www.microsoft.com/office/ork/xp/appndx/appa06.htmYou may need this on the same drive as the other tools. (Although wehave successfully used it elsewhere, others have reported problems).If you want to make Window help files you will need hcrtf.exe from aWindows compiler installation (this has been available for download atftp://ftp.microsoft.com/softlib/mslfiles/hcwsetup.exe).For large packages it is helpful to make zipped help and/or datafiles: for that you need zip and unzip from the Info-ZIP project(www.info-zip.org and mirrors, and included in our tools.zip).All of these need to be installed and in your path, and theappropriate environment variables set. Edit MkRules to set theappropriate paths as needed.BEWARE: if you have Norton Anti-Virus you may need to disable it.Some versions lock up the machine when windres is run.BEWARE: Don't expect this to work if the path to R_HOME contains spaces.At this point there are two approaches:1) Streamlined wayAssuming that ...\rw1040\bin is in your path, useRcmd INSTALL packagewhere `package' can be a directory or a .tar.gz file. SeeRcmd INSTALL --help for a full list of options, which include-l, --library=LIB install packages to library tree LIB--docs=TYPE type(s) of documentation to build and install--use-zip-data collect data files in zip archive--use-zip-help collect help and examples into zip archives--use-zip combine `--use-zip-data' and `--use-zip-help'TYPE can be "none" or "normal" or "chm" (the default) or "winhlp" or "all"2) Manual `full-control'For each package you want to install, unpack it to a directory, saymypkg, in R_HOME\src\library, and runcd R_HOME\src\gnuwin32make pkg-mypkgCustomising compilation=======================The Makefiles can be customized: in particular the name of the DLL canbe set (for example we once needed integrate-DLLNM=adapt), the compileflags can be set (see the examples in MakeDll) and the types of help(if any) to be generated can be chosen (variables HELP and WINHELP).The simplest way to customize the compilation steps is to set variables ina file src\Makevars.win, which will automatically be included by MakeDLL.For example, for RODBC src\Makevars.win could include the lineDLLLIBS+=-lodbc32or, equivalently,RODBC-DLLLIBS=-lodbc32If you have a file src\Makefile.win, that will be used as the makefilefor source compilation in place of our makefile MakeDll.BEWARE: files src\Makefile or src\Makevars will be used if they existand the .win equivalents do not. Such files included in packagesources are usually designed for use under Unix and are best removed.BEWARE: references to variables in R.dll are converted to theright form by using the header files. You must include them.Using zipped help files=======================You will need zip installed, of course. Just runmake ziponly-mypkgafter building mypkg. Target `ziphelp-mypkg' will make the zip filesbut not remove the separate files: this can be used for testing.This is an option to Rcmd INSTALL.Using zipped data files=======================You will need zip installed. Just runmake zipdata-mypkgafter building mypkg. This is recommended if you have either many smalldata files (as in package Devore5) or a few large data files.This is an option to Rcmd INSTALL.Checking and building packages==============================The equivalent of `R CMD check mypkg' on Unix isRcmd check mypkgUse `Rcmd check --help' for full details. There is an analogous call forbuild.You may need to set TMPDIR to a suitable temporary directory: thedefault is c:\TEMP.These have been used successfully under NT/2000. We have seenproblems with some Perl versions on Win 95/98/ME, but believe theseare now resolved. make pkgcheck-mypkg will perform the tests of theexamples and tests directory, as far as we know on all OSes.Debugging=========See the rw-FAQ.Using Visual C++================You may if you prefer use Visual C++ to make the DLLs (unless they useFortran source!). First build the import library R.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). A list of therelevant variables is in the file `exported-vars'.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, 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\rw1040\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().Simple Ports============If your package has no C nor Fortran nor C++ sources, several stepscan be omitted.You will needsuitable versions of Unix tools including make, sh, rm, sed, awk,mkdir, echo, cp and cat; we have packaged a set athttp://www.stats.ox.ac.uk/pub/Rtools/tools.zip.perl5, available via http://www.activestate.com/Products/ActivePerl/All of these need to be installed and in your path, and theappropriate environment variables set.For each package you want to install, unpack it to a directory, saymypkg, in RHOME\src\library, and runcd RHOME\src\gnuwin32make pkg-mypkgIf you have a Unix/Linux box, it will suffice to zip up the Unixinstallation of the package. Install the package, thencd `R RHOME`/libraryzip -rl /dest/mypkg.zip mypkg(the -l flag converts to CRLF line endings: it is not necessary butusers may want to read the information files in a Windows editor).zip is often installed on Linux machines, and sources and binaries forUnix boxes are available via the Info-Zip site given above.Non-standard locations======================You can specify the location of the package source by PKGDIR and thelibrary in which to install the package by RLIB, as inmake PKGDIR=/mysources RLIB=/R/library pkg-mypkgwhich installs the package in \mysources\mypkg as \R\library\mypkg.It may well be simpler to useRcmd INSTALL -l /R/library /mysources/mypkgCross-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 or .hlp files. For a package without compiledcode you can just zip up the Linux installation of the package.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, and check that Makefile has WINHELP set to NO.Make the import library bymake libR.aThen packages can be made as natively, for example bycd .../src/gnuwin32make STAMP=NO PKGDIR=/mysources RLIB=/R/win/library pkg-mypkgmake PKGDIR=/mysources RLIB=/R/win/library pkgcheck-mypkgcd /R/win/libraryzip -rl /dest/mypkg.zip mypkg(Rcmd is a Windows executable, so cannot be used. Notice the STAMP=NO line.)Feedback========Please send comments and bug reports to (preferably both of)Guido Masarotto <guido@hal.stat.unipd.it>Brian Ripley <ripley@stats.ox.ac.uk>