Cross-compiling Windows applications on Linux
Phil Blecker (tmwg@inxservices.com) has contributed these notes for
creating a cross-compiler that is capable of producing DOS/Windows binaries
from a Linux host.
These notes are for egcs on Linux for a cross-compiler system to
MS DOS/Windows.
Mingw32:
In the top level gcc directory, make a subdirectory for the
cross-compiler, such as mingw.
Untar the binutils in the empty mingw subdirectory. Type:
mv bfd binutils gas ld opcodes ..
cd include
for i in *.h ; do
if [ -f ../../include/$i ]; then rm -f $i ; fi
done
cd ..
mv include/* ../include
rm -rf *
This will tell gcc's configure to make bfd, opcodes, binutils, gas and ld
as cross-compilation tools as well as gcc. I want to use the common include
files from egcs, not from binutils. You might be able to just replace the
egcs files with the binutils.
Run configure as follows:
../configure --host=i586-pc-linux-gnu --build=i586-pc-linux-gnu
--target=i586-pc-mingw32
--with-gnu-ld --with-gnu-as --enable-threads=no
--with-gxx-include-dir=/usr/i586-pc-mingw32/sys-include/c++
--with-headers=/usr/i586-pc-mingw32/sys-include
--with-libs=/usr/i586-inX-mingw32/lib
--with-mmap --enable-bfd-assembler
--enable-languages="c,c++"
--enable-languages may not be available, depending on which egcs you're
using.
Replace the host and build with appropriate values for your system. You
can find out what they should be by typing:
../config-guess
You can change the i586 in i586-pc-mingw32 with something more appropriate
for your needs if you want. The i586 says that the cross-compiler will
default to code for a Pentium, unless told otherwise by -m options.
I don't believe that thread support has been implemented yet for MS,
although I also don't believe that it is used for anything but Objective-C.
I don't know for sure whether the --with directory options are
absolutely required. This is where the include files and libraries for MS
will be put by default, anyway. I've just included them in the configure
options because I put them in a slightly different place (with some
modifications to the gcc top level source file), so I don't know what
happens if they're not used. They won't hurt anything.
Now type:
make cross
If the make is successful, type:
make install-cross
The default setup is to put the cross-compilation tools in
/usr/local/bin. The include files and libraries will go into the
directories in the --with options. All the tools will be prefixed by
i586-pc-mingw32-*. To use the cross-compiler, you type i586-pc-mingw32-gcc.
These names must be left with that prefix, even if you alias
i586-pc-mingw32-gcc to something simple to type.
Now you can build the mingw32 distribution using the just built
cross-compiler. Install the include and library files in the directories
shown above. wxWidgets can be built using the GNU makefiles if the
cross-compiler is used instead of g++. Again, install the include files and
libraries to the directories shown above.
I need to add the following to libio/stdiostream.h, after the include
for stdio.h:
#ifdef __MINGW32__
#include <io.h>
#endif
I have been told that this is the wrong change, and that it would be fixed
in the mingw32 distribution. I don't know if that has been done or not,
though, because I haven't updated mingw32 for a while.
Cygwin:
In the top level gcc directory, make a subdirectory for the
cross-compiler, such as cygwin.
Untar the cygwin development distribution in the empty cygwin
subdirectory. Type:
mv bfd binutils gas intl ld libtermcap mmalloc newlib opcodes readline winsup ..
cd include
for i in *.h ; do
if [ -f ../../include/$i ]; then rm -f $i ; fi
done
cd ..
mv include/* ../include
rm -rf *
This will tell gcc's configure to make bfd, opcodes, binutils, gas and ld
as cross-compilation tools as well as gcc and the Cygwin support libraries
and DLLs. I want to use the common include files from egcs, not from
Cygwin. You might be able to just replace the egcs files with the Cygwin
include files.
Run configure as follows:
../configure --host=i586-pc-linux-gnu --build=i586-pc-linux-gnu
--target=i586-pc-cygwin32
--with-gnu-ld --with-gnu-as --enable-threads=no
--with-gxx-include-dir=/usr/i586-pc-cygwin32/sys-include/c++
--with-headers=/usr/i586-pc-cygwin32/sys-include
--with-libs=/usr/i586-inX-cygwin32/lib
--includedir=/usr/i586-pc-cygwin32/sys-include
--libdir=/usr/i586-inX-cygwin32/lib
--with-mmap --enable-bfd-assembler
--enable-languages="c,c++"
--enable-languages may not be available, depending on which egcs you're
using.
Replace the host and build with appropriate values for your system. You
can find out what they should be by typing:
../config-guess
You can change the i586 in i586-pc-cygwin32 with something more appropriate
for your needs if you want. The i586 says that the cross-compiler will
default to code for a Pentium, unless told otherwise by -m options.
I don't believe that thread support has been implemented yet for MS,
although I also don't believe that it is used for anything but Objective-C.
I don't know for sure whether the --with directory options are
absolutely required. This is where the include files and libraries for MS
will be put by default, anyway. I've just included them in the configure
options because I put them in a slightly different place (with some
modifications to the gcc top level source file), so I don't know what
happens if they're not used. They won't hurt anything.
I have both mingw32 and cygwin32 cross-development on the same Linux
system. I don't actually build the binutils from the Cygwin distribution.
I've simply linked the i586-pc-mingw32-* names to i586-pc-cygwin32-*. There
may be problems building the binutils packages that I'm not aware of.
Now type:
make cross
If the make is successful, type:
make install-cross
The default setup is to put the cross-compilation tools in
/usr/local/bin. The include files and libraries will go into the
directories in the --with options. All the tools will be prefixed by
i586-pc-cygwin32-*. To use the cross-compiler, you type i586-pc-cygwin32-gcc.
These names must be left with that prefix, even if you alias
i586-pc-cygwin32-gcc to something simple to type.
Now you can build the cygwin32 distribution using the just built
cross-compiler. Install the include and library files in the directories
shown above. wxWidgets can be built using the GNU makefiles if the
cross-compiler is used instead of g++. Again, install the include files and
libraries to the directories shown above.