From ripley@stats.ox.ac.uk  Thu Apr 27 07:30:48 2000
From: ripley@stats.ox.ac.uk (Prof Brian D Ripley)
Date: Thu, 27 Apr 2000 07:30:48 +0100 (BST)
Subject: [Rd] Cross compiling a package for Windows on Linux
In-Reply-To: <m12karq-000ZSaC@franz.stat.wisc.edu>
Message-ID: <Pine.GSO.4.05.10004270708090.26167-100000@auk.stats>

On Wed, 26 Apr 2000, Douglas Bates wrote:

> I would like to compile for Windows a rather simple R package that
> contains some C code.  It does not contain any Fortran code.
> 
> I tried the cross-compilation route using the pre-built set of tools
> from http://www.devolution.com/~slouken/SDL/Xmingw32/, as described in
> $R_SRC/src/gnuwin32/INSTALL
> 
> Using the sources in r-devel from the rsync site I am able to build
> libR.a in src/gnuwin32 but I can't build the package.  Using the

Almost certainly you built an incorrect libR.a from the evidence below.

> sources in r-release-patched from the rsync site I am unable to build
> libR.a.  The tail end of that compilation log is
> 
>  $ cd r-release/src/gnuwin32/
>  $ make
>  mkdir -p ../../bin 
>  make -C ./fixed

...

If you use Makefile you are trying to build R, and you can't do that
without Fortran.  To build just a package you need Makefile.packages
and the distributed R.exp file.


>  make[1]: Entering directory `/usr/src/r-release/src/gnuwin32/fixed'
>  -------- Building ../../../library/base/R/Rprofile from ../../library/profile/Common.R ../../library/profile/Rprofile.gnw--------
>  mkdir -p ../../../library/base/R
>  cat  ../../library/profile/Common.R ../../library/profile/Rprofile.gnw > ../../../library/base/R/Rprofile
>  sed -e '/^#/d' -e '/Rsockfork/d' -e 's/F77_SUBROUTINE(\(.*\))/void * \1_();/' -e 's/C_FUNCTION(\(.*\))/void * \1();/' ../../appl/ROUTINES > ../../include/FFDecl.h
>  sed -e '/^#/d' -e '/Rsockfork/d' -e 's/F77_SUBROUTINE(\(.*\))/	{ "\1_",	\1_},/' -e 's/C_FUNCTION(\(.*\))/{ "\1",	\1 },/' ../../appl/ROUTINES > ../../include/FFTab.h
>  sh ./GETCONFIG > ../../include/Rconfig.h
>  sh ./GETVERSION > ../../include/Rversion.h
>  cp -p ./h/config.h ./h/psignal.h ../../include
>  echo done > fixh
>  (cd ../../../doc; \
>  cat html/search/SearchEngine-head.html > html/search/SearchEngine.html; \
>  perl ../src/gnuwin32/fixed/keywords2html KEYWORDS.db >> html/search/SearchEngine.html; \
>  cat html/search/SearchEngine-foot.html >> html/search/SearchEngine.html)
>  cp -p ./r/*.html ../../../doc/html
>  echo done > fixr
>  cp -p  bin/Rd2dvi.sh bin/Rd2txt.bat bin/Rdconv.bat bin/Rdindex.bat bin/Sd2Rd.bat bin/fwf2table bin/helpPRINT.bat ../../../bin
>  echo done > fixbin
>  cp -p etc/Rconsole etc/Rdevga etc/Rprofile etc/rgb.txt ../../../etc
>  echo done > fixetc
>  ...  (many lines deleted)
>  i386-mingw32-gcc -isystem /packages/R-X/i386-mingw32/include   -O2 -Wall -pedantic -I../include -I../include/R_ext -DHAVE_CONFIG_H  -c zeroin.c -o zeroin.o
>  i386-mingw32-g77 -O2 -Wall -pedantic  -c blas.f -o blas.o
>  make[1]: i386-mingw32-g77: Command not found
>  make[1]: *** [blas.o] Error 127
>  make[1]: Leaving directory `/usr/src/r-release/src/appl'
>  make: *** [rlibs] Error 2
>  $ make libR.a
>  i386-mingw32-gcc -isystem /packages/R-X/i386-mingw32/include   -O2 -Wall -pedantic -I../include -I../include/R_ext -I. -DHAVE_CONFIG_H  -c console.c -o console.o
>  i386-mingw32-gcc -isystem /packages/R-X/i386-mingw32/include   -O2 -Wall -pedantic -I../include -I../include/R_ext -I. -DHAVE_CONFIG_H  -c dataentry.c -o dataentry.o
>  i386-mingw32-gcc -isystem /packages/R-X/i386-mingw32/include   -O2 -Wall -pedantic -I../include -I../include/R_ext -I. -DHAVE_CONFIG_H  -c devga.c -o devga.o
>  i386-mingw32-gcc -isystem /packages/R-X/i386-mingw32/include   -O2 -Wall -pedantic -I../include -I../include/R_ext -I. -DHAVE_CONFIG_H  -c dodevga.c -o dodevga.o
>  i386-mingw32-gcc -isystem /packages/R-X/i386-mingw32/include   -O2 -Wall -pedantic -I../include -I../include/R_ext -I. -DHAVE_CONFIG_H  -c dounzip.c -o dounzip.o
>  i386-mingw32-gcc -isystem /packages/R-X/i386-mingw32/include   -O2 -Wall -pedantic -I../include -I../include/R_ext -I. -DHAVE_CONFIG_H  -c dynload.c -o dynload.o
>  i386-mingw32-gcc -isystem /packages/R-X/i386-mingw32/include   -O2 -Wall -pedantic -I../include -I../include/R_ext -I. -DHAVE_CONFIG_H  -c edit.c -o edit.o
>  i386-mingw32-gcc -isystem /packages/R-X/i386-mingw32/include   -O2 -Wall -pedantic -I../include -I../include/R_ext -I. -DHAVE_CONFIG_H  -c extra.c -o extra.o
>  extra.c: In function `Rwin_fpset':
>  extra.c:452: warning: implicit declaration of function `_fpreset'
>  extra.c:453: warning: implicit declaration of function `_controlfp'
>  extra.c:453: `_MCW_EM' undeclared (first use in this function)
>  extra.c:453: (Each undeclared identifier is reported only once
>  extra.c:453: for each function it appears in.)
>  make: *** [extra.o] Error 1
>  $ i386-mingw32-gcc --version
>  2.95.2

I think you omitted to customize MkRules: it seems highly unlikely that
/packages/R-X/i386-mingw32/include is correct for you (it is from my
system): INSTALL says

> Edit MkRules to set BUILD=CROSS and the appropriate paths as needed.

and you need to set HEADER.  In any case, you are getting the wrong
headers.

> With the sources from r-devel, which have been changed today, I can
> generate libR.a but I cannot build a library, even with libR.a.  
> I tried building the nls library just as a test.  The errors reported
after 
> make pkg-nls are
> 
>  $ make pkg-nls

[...]

Looks like libR.a is wrong as R.exp is corrupt (probably empty). When I try
`make libR.a' on R-devel it behaves as for R-release.

The short answer is that you need R.exp, and to get that you need either to
build the whole of R (for which you need g77) or get the one in rwxxxxsp.  
What I suggest you do is to unpack rw1001 (you'll need I think the just
rw1001b? and rw1001sp zip files) and use that. The binary distribution has
the correct Makefile and supplies R.exp.  Last time I tried that
cross-compiled out of the box.

As you noted, I am in the process of changing the Makefiles and
instructions, mainly because the Cygwin release has changed and (aargh!)
not longer has a fully functional make, and the header set has also
changed.  It's a rash assumption that the R-devel or R-release-patched
will cross-compile as we only test that occasionally, including just before
release.

Brian

-- 
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-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


[Rd] Cross compiling a package for Windows on Linux
Prof Brian D Ripley