"Fossies" - the Fresh Open Source Software Archive

Member "R-3.6.0/src/gnuwin32/README.packages" (25 Sep 2018, 4712 Bytes) of package /linux/misc/R-3.6.0.tar.gz:


As a special service "Fossies" has tried to format the requested text file into HTML format (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the last Fossies "Diffs" side-by-side code changes report for "README.packages": 3.4.2_vs_3.4.3.

    1 Writing packages for R
    2 ======================
    3 
    4 See the Writing R Extensions manual for a full description of how
    5 to write a package.
    6 
    7 
    8 Building from a source-code library under Windows
    9 =================================================
   10 
   11 Instructions for installing the toolset and building packages using the
   12 standard methods are in the `R Installation and Administration' manual
   13 (which is available in various formats as R-admin.* in the doc/manual
   14 directory).
   15 
   16 This file contains instructions for non-standard situations:
   17 
   18  - Using Microsoft Visual C++
   19  - Using Borland C++
   20  - Using other compilers and languages
   21 
   22 All the examples given here have worked at some point with 32-bit R,
   23 but are mainly of historical interest.
   24 
   25 
   26 Using Visual C++
   27 ================
   28 
   29 You may if you prefer use Visual C++ to make the DLLs (unless they use
   30 Fortran source!). The notes here were tested with VC++6.
   31 
   32 First build the import library Rdll.lib by (from the sources)
   33 
   34 	make R.exp
   35 
   36 	lib /def:R.exp /out:Rdll.lib
   37 or, depending on your version of VC++
   38 	link /lib /def:R.exp /machine:x86 /out:Rdll.lib
   39 
   40 Another way to make R.exp is to use pexports.exe from mingw-utils,
   41 e.g. pexports R.dll > R.exp.
   42 
   43 Then you can compile the objects and build the DLL by
   44 
   45 	cl /MT /Ox /D "WIN32"  /c *.c
   46 	link /dll /def:mypkg.def /out:mypkg.dll *.obj Rdll.lib
   47 
   48 where you will need to create the .def file by hand listing the entry
   49 points to be exported.  (If there are just a few you can use /export
   50 flags instead.) If the C sources use R header files you will need to
   51 arrange for these to be searched, perhaps by including in the cl line
   52 
   53 	/I ..\..\..\include
   54 
   55 If you build a debug version of the DLL in the development
   56 environment, you can debug the DLL code there just by setting the
   57 executable to be debugged as the full path to the R front-end.
   58 
   59 Extra care is needed when referencing variables (rather than
   60 functions) exported from R.dll.  These must be declared
   61 __declspec(dllimport) (as in R's own header files).  
   62 
   63 For some applications making use of the R API headers you will need to
   64 build import libraries for Rblas.dll or graphapp.dll and link against
   65 those.
   66 
   67 VC++6 lacks some standard functions such as isnan and isfinite.  To use
   68 R's macros you will need
   69 
   70 #undef ISNAN
   71 #define ISNAN(x) _isnan(x)
   72 #undef R_FINITE
   73 #define R_FINITE(x) _finite(x)
   74 
   75 for example.  Even then, we have seen examples of IEC60559 arithmetic
   76 being performed incorrectly.
   77 
   78 
   79 Using Borland C++
   80 =================
   81 
   82 Borland C++5.5 is available as a free download from
   83 http://www.borland.com/bcppbuilder/freecompiler/ and as part of C++
   84 Builder 5.  The following will make convolve.dll from convolve.c (flag
   85 -6 optimizes for a Pentium Pro/II/III/4, and -u- removes extra underscores)
   86 
   87 bcc32 -u- -6 -O2 -WDE convolve.c
   88 
   89 You can build an import library for R.dll by
   90 
   91 make R.exp
   92 implib R.lib R.exp
   93 
   94 and then add R.lib to the bcc32 command line, for example (from
   95 Venables & Ripley's `S Programming')
   96 
   97 bcc32 -u- -6 -O2 -WDE -I\R\R-2.3.0\src\include VCrndR.c R.lib
   98 
   99 We believe that when referencing variables (rather than functions)
  100 exported from R.dll these must be declared __declspec(dllimport) just
  101 as for VC++.
  102 
  103 
  104 Using other compilers and languages
  105 ===================================
  106 
  107 To use C++ see the section in the R for Windows FAQ.  You can include
  108 C++ code in packages and the supplied Makefiles will compile with g++
  109 and link the DLL using g++ (and hence link against libstdc++).  Use of
  110 C++ I/O may or may not work, and has been seen to crash R.
  111 
  112 To use F90 or F95, see `Writing R Extensions'.
  113 
  114 For other compilers you will need to arrange to produce a DLL with
  115 cdecl (also known as _cdecl or __cdecl) linkage.  The MinGW port (and
  116 VC++) uses no `name mangling' at all, so that if for example your
  117 compiler adds leading or trailing underscores you will need to use the
  118 transformed symbol in the call to .C in your R code.  Many compilers
  119 can produce cdecl DLLs by a suitable choice of flags, but if yours
  120 cannot you may need to write some `glue' code in C to interface to the
  121 DLL.
  122 
  123 If you use .Fortran this appends an underscore and does no case
  124 conversion at all to the symbol name.  It is normally best to use .C
  125 with compilers other than gfortran and map the name manually if
  126 necessary.
  127 
  128 Care is needed in passing character strings to and from a DLL by .C:
  129 they must be equivalent to the C type char** and null-terminated.  Not
  130 even the MinGW g77 Fortran used null-terminated strings. (g77 was in
  131 GCC 3.x.y, superseded by gfortran.)
  132 
  133 WARNING: DLLs made with some compilers reset the FPU in their startup
  134 code and this will cause operations such as
  135 0./0. to crash R.  You can re-set the FPU to the correct values by a
  136 call to the C entry point Rwin_fpset().
  137