Cross-compilation from Win32 to GO32v2

From Lazarus wiki
Revision as of 12:55, 3 June 2008 by B.Nafz (talk | contribs) (Added "short way" to generate DOS-Progs (tested under Win98/2000/XP).)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

A simple way to generate plain-DOS progs under Win32 is the following: Install the Go32V2-Version under Win32 in e.g. \ppdos (Note: The last errorfree FPC-DOS-Version is 2.02. The 2.04-Version produces difficult to find errors (you may test this with a short program which simply includes the graph Unit) - pls. look at bug reports for more details). Install an actual 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 corse you have to inform the compiler (via command line switches) about the location of your units..). The resulting *.exe runs fine as _long_ as a dpmi-Interface ist present (you may distribute your *.exe together with cwsdpmi.exe which is in your fpc-directory). If you don't want a separate dpmi-Interface you may use one of the ways described below or compile your programm 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 led 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).

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 them to 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).

You still 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.

Another article related to cross-compilation in FPC can be found in Lazarus Wiki, documentation for building the compiler (including some information about cross-compilation) can be found in buildfaq.pdf document.