AUTHOR: Nathan Coulson (nathan@linuxfromscratch.org) DATE: 2005-01-14 LICENSE: GNU Free Documentation License SYNOPSIS: Cross Compiling from linux to various operating systems VERSION: 0.5 DESCRIPTION: Have you ever wanted to develop on linux, but compile programs for windows [mingw32], or dos [djgpp]? This hint shows the user how they can build their own cross-compiler. HINT: First to cover some of the basics. First you have to build binutils. After that, you must copy the header files for your standard C library into i{3,4,5,6}86-pc-*/include directory. Next you can build gcc. This toolcain will be used to compile your ew library, so you would recompile binutils, compile your standard C library, then compile gcc. I am using /opt/tmpcross as a temporairy place to put temporairy compiler tools. This directory can be deleted when you are done building a toolchain There are 3 flags that control cross compiling, --build, --host, and --target. --build is meant for the machine you are building on, --host is the machine the program is meant to run on, while --target is what machine the program you are compiling will produce binaries for. Please note that --target is only useful on binutils, gcc, and simular programs. As an example, to compile a version of binutils from x86 linux, that will run on windows, but create executables that are meant to be run on dos you may use configure --build=i686-pc-linux-gnu --host=i686-pc-mingw32 --target=i686-pc-msdosdjgpp Variables ========= export PATH=/opt/tmpcross/bin:/opt/cross/bin:${PATH} i686-pc-mingw32 =============== Mingw is a collection of freely avaliable and freely distributable Windows specific header files and import libraries combined with GNU toolsets that allow one to produce native Windows programs that do not rely on any 3rd-party DLLs. FILES ----- binutils-2.15.tar.bz2 [ftp://ftp.gnu.org/gnu/binutils] gcc-3.4.3.tar.bz2 [ftp://ftp.gnu.org/gnu/gcc] mingw-runtime-3.6-src.tar.gz [http://www.sf.net/projects/mingw] w32api-3.2-src.tar.gz [http://www.sf.net/projects/mingw] BINUTILS-PASS1 -------------- tar -xjf binutils-2.15.tar.bz2 mkdir binutils-build cd binutils-build ../binutils-2.15/configure --prefix=/opt/tmpcross \ --target=i686-pc-mingw32 make make install W32API-HEADERS -------------- tar -xzf w32api-3.2-src.tar.gz cd w32api-3.2 cp -r include /opt/tmpcross/i686-pc-mingw32/ MINGW-RUNTIME-HEADERS --------------------- tar -xzf mingw-runtime-3.6-src.tar.gz cd mingw-runtime-3.6 cp -r include /opt/tmpcross/i686-pc-mingw32/ GCC-PASS1 --------- tar -xjf gcc-3.4.3.tar.bz2 mkdir gcc-build cd gcc-build ../gcc-3.4.3/configure --prefix=/opt/tmpcross \ --enable-languages=c --target=i686-pc-mingw32 \ --disable-nls --disable-threads --without-headers make make install BINUTILS-PASS2 -------------- tar -xjf binutils-2.15.tar.bz2 mkdir binutils-build cd binutils-build ../binutils-2.15/configure --prefix=/opt/cross \ --target=i686-pc-mingw32 make make install W32API ------ tar -xzf w32api-3.2-src.tar.gz cd w32api-2.3 ./configure --prefix=/opt/cross-i686-pc-mingw32 \ --host=i686-pc-mingw32 make make install MINGW-RUNTIME ------------- We also untar w32api, since mingw-runtime looks in ../w32api/include when compiling tar -xzf w32api-3.2-src.tar.gz tar -xzf mingw-runtime-3.6-src.tar.gz mv w32api-2.3 w32ai cd mingw-runtime-3.6 ./configure --prefix=/opt/cross/i686-pc-mingw32 \ --build=`gcc -dumpmachine` --host=i686-pc-mingw32 make make install GCC-STAGE2 ---------- tar -xjf gcc-3.4.3.tar.bz2 mkdir gcc-build cd gcc-build ../gcc-3.4.3/configure --prefix=/opt/cross \ --enable-languages=c,c++ --target=i686-pc-mingw32 \ --enable-threads=win32 make make install i686-pc-cygwin ============== i586-pc-msdosdjgpp ================== djgpp is a port of gcc for dos. I have a target of i586, since the djlsr package refers to it (although I have been unsuccessful at compilng it) FILES ----- binutils-2.15.tar.bz2 [ftp://ftp.gnu.org/gnu/binutils] gcc-3.4.3.tar.bz2 [ftp://ftp.gnu.org/gnu/gcc] djcrx203.zip [ftp://ftp.delorie.com/pub/djgpp/current/v2] BINUTILS -------- tar -xjf binutils-2.15.tar.bz2 mkdir binutils-build cd binutils-build ../binutils-2.15/configure --prefix=/opt/cross \ --host=`gcc -dumpversion` --target=i586-pc-msdosdjgpp make make install DJCRX ----- Please note that these libraries are precompiled. I have not been able to compile djlsr203.zip with a updated gcc. I do not know what stubify is for, but it is required for compiling binaries mkdir djcrx203 cd djcrx203 unzip ../djcrx203.zip cp -r include/lib /opt/cross/i586-pc-msdosdjgpp gcc src/stub/stubify.c -o /opt/cross/i586-pc-msdosdjgpp/bin GCC --- I cannot compile C++ at the moment, so I only build C tar -xjf gcc-3.4.3.tar.bz2 mkdir gcc-build cd gcc-build ../gcc-3.4.3/configure --prefix=/opt/cross \ --enable-languages=c --host=`gcc -dumpmachine` \ --target=i586-pc-msdosdjgpp --enable-threads=single make make install ACKNOWLEDGEMENTS: Thanks to Seth W. Klein who helped me test and debug the origional lin2win.txt hint. CHANGELOG: [2005-01-14] * Updated software * Simplified instructions [2003-06-03] * Initial Hint