Cross-compilation from Win32 to GO32v2

From Lazarus wiki
Revision as of 07:40, 13 April 2012 by Chronos (talk | contribs) (category)
Jump to navigationJump to search

Template:Translate

In general, FPC support of cross-compilation expects you to have "cross-tools" (assembler and linker), i.e. tools running on the source platform, but creating binaries for (a different) target platform in your usual "bin" directory (i.e. i386-win32 for your Win32 installation). Filenames of these tools should be prefixed with the target platform specification (e.g. "i386-linux-as.exe" or "i386-go32v2-ld.exe").

When talking specifically about GO32v2 target under Win32, there are two possible ways how to get this. The general way (possible for GO32v2 too) is to compile real cross-tools, i.e. compile the GO32v2 version of as.exe with GNU C for Win32 (Cygwin or MingW32) to get real Win32 binary producing outputs for GO32v2. This is the only possible solution for platforms for which there isn't emulation layer for running "their" binaries (Linux, FreeBSD, Netware etc.). Pre-compiled cross-tools for some host-guest combinations are available on our FTP server - if you build those tools for other combinations, or build (and successfully test) newer versions of existing ones, you are welcome to contribute them.

The second possibility is to take the advantage of WinXX being able to run DOS binaries and just copy the GO32v2 versions of GNU tools to a new location and different name. This has some limitations (e.g. with regard to maximum length of the command line), but it works in general (although I wouldn't consider this solution really supported one - however, it's an easier one).

The third possibility is using DOS emulation provided by WinXX to avoid cross-compilation. If this works for you (see "Creating GO32v2 binaries under WinXX DOS box" below for more detailed information), this is the easiest solution. However, you are completely on your own there, since the WinXX emulation of DOS is far from being perfect and different WinXX versions impose various different limitations and issues one may need to face.

In any case, you need both RTLs available, of course. One additional issue here is that the GO32v2 compiler expects the RTL in /units/go32v2/rtl (to allow it to run even in plain DOS which suffers from 8.3 name length constraint), whereas the Win32 compiler (including that one integrated in our IDE) expects directories with full target names (i386-go32v2), so you need to either rename the directory distributed together with the native GO32v2 release (if you don't intend to use the native GO32v2 compiler any more), or create a copy.

Finally, cross-debugging (debugging of GO32v2 binaries in Win32 IDE) isn't possible at the moment. The only possibility is to use GO32v2 IDE (or standalone GO32v2 gdb) directly.

More information on cross-compilation with FPC may be found in Cross compiling and Cross compiling for Win32 under Linux (the latter primarily referring to Lazarus, but containing general FPC information too). Documentation for building the compiler (including some information about cross-compilation) may be found in buildfaq document.


Creating GO32v2 binaries under WinXX DOS box

A simple way to generate plain-DOS progs under Win32 is the following: Install the Go32V2 version under Win32 in e.g. \ppdos. Install an current Win32 version of fpc in e.g. \ppwin. Do your development with the Win32 version. After all runs and is fine use a Dos box (or a command-shell) and compile your source code via the command-line version of Go32v2 (of course you have to inform the compiler (via command line switches) about the location of your units..). The resulting *.exe runs fine as _long_ as DPMI is present (you may distribute your *.exe together with cwsdpmi.exe which is in your fpc directory). If you don't want a separate DPMI host you may use one of the ways described below or compile your program under plain DOS (in Win98 it suffices to boot in DOS mode and compile from there). To avoid problems with "long file names" you may use the "subst"-Command to access your files e.g. "subst b: c:\documents...." would let you find all files in b: which are located in c:\documents... (this is also a fine solution if you work in a cmd shell or Dos box and are annoyed by the long names of the Win32 directory structure).