This is the mail archive of the crossgcc@sources.redhat.com mailing list for the crossgcc project.

See the CrossGCC FAQ for lots more information.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Updated Cross-Compile How-To (Using Linux to Compile Windows Programs)


Here is an updated cross-compile how-to.  This is based on the sources found at
the www.mingw.org site on 14-Jan-2001. I would very much like to see a few of
the sources patched so that some of the steps can be avoided.  If I have the
time I will generate and send in the patches to the Makefile.am, etc. so that it
works better out of the box.  To whom should I send that?

I will try to make this into an html file.  Also, if netscape foobar'd the
formatting of this email, let me know and I can send the text file as an
attachment.

Comments, errors, suggestions, etc. welcome.  Of course, I am not on either
list, bla bla bla.

--Bill

====


Last Updated: 14-Jan-2002 by Bill Adams (email intentionally left out)



A quick and dirty (and updated) version of how to set up cross
compiling from Linux to MS Windows.  If you do not understand any of
the steps below then you probably want to build your command-line
skills in building native programs before attempting to cross-compile
anything.

Much of this was stolen (and updated) from the 'cross.sh' script that
can be found at
http://www.devolution.com/~slouken/SDL/Xmingw32/crossgcc/index.html

Also, you may want to read http://gcc.gnu.org/install/ before
attempting this. There is good information there.



1. --binutils--

o Get the latest version of binutils from the www.mingw.org download
site (on sourceforge at the time of this writing).

o Unpack: tar xfvvz binutils-xx.tar.gz

o cd into the source directory: cd binutils-xx

o Configure:  Be ABSOLUTELY sure that you set a prefix that will not
overwrite your real bin-utils.  Also, set the target:
./configure --prefix=/usr/local/cross-compile --target=i386-mingw32msvc

o Build: make
Note: If you get an error while building that reads like "./../ylwrap:
-d: command not found" or similar, you are probably missing lex and/or
yacc.  They can be found in the GNU packages 'flex' and 'byacc'
respectively.  Be sure to re-configure the binutils source if you end
up having to install either said package.

o Install: su; make install


*NOTE* before you complete any of the steps below, be sure that you
put the new PREFIX/bin in your path.  E.g. in bash:
export PATH=/usr/local/cross-compile/bin:$PATH


2. -- include files --

o This is the chicken and egg step where you need to get the include
files installed before you can build gcc.

o Download mingw-runtime.

o Recursive copy the include directory into your PREFIX/mingw-ver
directory, e.g.:
cp -Rv mingw-runtime-1.2/include /usr/local/cross-compile/i386-mingw32msvc


3. -- gcc --

o Download the source, Unpack it, cd into the source directory.

o Download the 'gcc-2.95.2-libio-patch' from
http://www.devolution.com/~slouken/SDL/Xmingw32/crossgcc/index.html

o Apply the patch with 'patch -p1 <gcc-2.95.2-libio-patch'. Yes this
patch still works with gcc-2.95.3-20011106-beta.  As a note for posterity,
this patch basically changes the Makefile.in to include (-I) the
$(build_tooldir) and libio/gen-params to use -specs=${gccdir}/specs.

o Configure.  Again, use the same prefix and be sure to specifically one
that will not overwrite your real gcc.

./configure  -v --prefix=/usr/local/cross-compile \
             --target=i386-mingw32msvc \
             --with-gnu-as --with-gnu-ld --disable-multilib


o To prevent the make from failing:
cd i386-mingw32msvc
ln -s ../install-sh .
ln -s ../config.sub .
ln -s ../include include
cd libiberty
./configure --with-the-options-you-used-above
cd ../..

o Build: make  (...get something to eat. This takes a while ;-)

o Install: make install



4. -- w32api libs --

o Download and unpack the w32api libs.

o ./configure --prefix=/usr/local/cross-compile --target=i386-mingw32msvc

o Edit the Makefile.  You need to change all programs such that they
have the $(target_alias)- in front of them, eg: "CC = gcc" becomes
"CC = $(target_alias)-gcc".  Do this for gcc, ar, dlltool, ld, and as.

o Build: make

o Install: make install

o You need to link the libraries:
cd /usr/local/cross-compile/i386-mingw32msvc/lib
for i in ../../lib/*; do ln -s $i .; done


5. -- mingw-runtime --

o Download, unpack, and configure (same options) the package.

o Edit the Makefile as for w32api.

o make; make install


6. -- Test the Program --

o Create hello.c (from documentation section of www.mingw.com):
#include <stdio.h>

int main(int argc, char **argv)
{
   printf ("Hello\n");
   return (0);
}

o Copy crt2.o into the same directory as your source (is there a better
way to do this?)
cp /usr/local/cross-compile/lib/crt2.o .

o Compile:
/usr/local/cross-compile/bin/i386-mingw32msvc-gcc \
  -I/usr/local/cross-compile/i386-mingw32msvc/include \
   -L/usr/local/cross-compile/lib \
  hello.c -o hello.exe

o Test it on a Windows box at a dos prompt.





------
Want more information?  See the CrossGCC FAQ, http://www.objsw.com/CrossGCC/
Want to unsubscribe? Send a note to crossgcc-unsubscribe@sources.redhat.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]