Skip to content

Cross compiling a package for Windows on Linux

4 messages · Douglas Bates, Brian Ripley, Peter Dalgaard

#
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
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
 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


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
 make DLLNM=  EXTRADOCS= \
   -C /usr/src/r-devel/src/library/nls PKG=nls RHOME=/usr/src/r-devel RLIB=/usr/src/r-devel/library \
   -f /usr/src/r-devel/src/gnuwin32/MakePkg
 make[1]: Entering directory `/usr/src/r-devel/src/library/nls'
 ---------- Making package nls ------------
 mkdir -p /usr/src/r-devel/library/nls
 cp -r   ./DESCRIPTION  ./INDEX  ./TITLE  /usr/src/r-devel/library/nls/
 cp: ./DESCRIPTION: No such file or directory
 make[1]: [/usr/src/r-devel/library/nls/zzzz] Error 1 (ignored)
 make -C ./src RHOME=/usr/src/r-devel \
   -f /usr/src/r-devel/src/gnuwin32/MakeDll DLLNAME=nls
 make[2]: Entering directory `/usr/src/r-devel/src/library/nls/src'
 ------- Building nls.dll from nls.a --------
 echo LIBRARY nls > nls.def
 echo EXPORTS >> nls.def
 i386-mingw32-nm nls.a > Defs
 sed -n "/^........ [BCDRT] _/s/^........ [BCDRT] _/ /p" Defs >> nls.def
 i386-mingw32-gcc  -mdll -Wl,--base-file,nls.b -s  -o nls.dll  nls.a  -L/usr/src/r-devel/src/gnuwin32   -lR 
 i386-mingw32-dlltool -k --as i386-mingw32-as   --dllname nls.dll  --base-file nls.b --output-exp nls.e --def nls.def
 i386-mingw32-gcc  -mdll  -Wl,--base-file,nls.b -s  -o nls.dll nls.e nls.a  -L/usr/src/r-devel/src/gnuwin32   -lR 
 nls.a(nls.o)(.text+0x203):nls.c: undefined reference to `Rf_asLogical'
 nls.a(nls.o)(.text+0x20f):nls.c: undefined reference to `Rf_isNewList'
 nls.a(nls.o)(.text+0x223):nls.c: undefined reference to `Rf_error'
 ...  (many lines deleted)
 nls.a(nls.o)(.text+0xb52):nls.c: undefined reference to `Rf_setAttrib'
 nls.a(nls.o)(.text+0xb5c):nls.c: undefined reference to `Rf_unprotect'
 make[2]: *** [nls.dll] Error 1
 make[2]: Leaving directory `/usr/src/r-devel/src/library/nls/src'
 make[1]: *** [src/nls.dll] Error 2
 make[1]: Leaving directory `/usr/src/r-devel/src/library/nls'
 make: *** [pkg-nls] Error 2

Do I need to go back and build a cross-compiler for g77 and start from
scratch?
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
On Wed, 26 Apr 2000, Douglas Bates wrote:

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

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.
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
and you need to set HEADER.  In any case, you are getting the wrong
headers.
after
[...]

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
#
Prof Brian D Ripley <ripley@stats.ox.ac.uk> writes:
It did last night, though (R-1-0-patches, that is).
#
Peter Dalgaard BSA <p.dalgaard@biostat.ku.dk> writes:
..as does R-devel as of this moment.