Introduction
Ever had those programming assignements from professors who can only run windows? Tired of spending expensive Gbs of HD just to keep a runing copy of windoze so you can compile your programs for windows? Spending hours booting the system just to find an uninitialized pointer bug? Want to change your operational system behaviour using buffer overflow? YOUR PROBLEMS ARE OVER!
Whatever are your needs this guide will teach you how to build mingw32 on linux. It can be used to compile C and C++ code for windows machines. But be aware, linux system calls will not work (like fork, system, etc).
Before you begin you will need...
- A copy of binutils source code
This can be found in several places. If you have installed gentoo from stage 1 you probably have o copy of it on your distfiles directory. Otherwise you can get them by emerging binutils or downloading them from here. - A copy of gcc source code
Same as binutils. You can also get it here. - A copy of the precompiled win32 api (they need to be compiled for win32 and you don't have a compiler yet
)
This one can be found on MinGW site on the download page. Click here for a direct download link. - A copy of the precompile mingw32 runtime library
Same as above. The direct link is here.
- Decompress everything on the right place.
Easier said than done...
You have to decompress everything in specific directories for it to work. It took me sometime to figure these out. First choose an location for the binaries/headers you you compile. I choosed /usr/local/cross-tools. Any directory will work. You will also have to choose a temporary directory for the compilling job. I used /root/cross. PS: You don't need to be root to do this unless you want the binaries available to everyone on the system.
After choosing the directories it's time to start decompressing. Copy everyone of the tars to /root/cross/source and:Code: Select all
mkdir /usr/local/cross-tools/i386-mingw32msvc cd /usr/local/cross-tools/i386-mingw32msvc gzip -dc "/root/cross/source/mingw-runtime=3.0.tar.gz" | tar xf - gzip -dc "/root/cross/source/w32api-2.3.tar.gz" | tar xf - cd /root/cross/source gzip -dc "/root/cross/source/binutils-2.13.90-20030111-1-src.tar.gz" | tar xf - gzip -dc "/root/cross/source/gcc-3.2.3-20030504-1.tar.gz" | tar xf - - Configure binutils
You will want your source code for binutils and gcc imaculate in case you make something wrong in the LONG configuring/making process. Starting over is no fun. So lets create some directories to store the configuration.Then thanks God for bash auto-completion command (TAB) and run these commands(be sure to change the directories for your configuration):Code: Select all
mkdir /root/cross/binutils-i386-mingw32msvc mkdir /root/cross/gcc-i386-mingw32msvcCode: Select all
cd /root/croos/binutils-i386-mingw32msvc /root/cross/source/binutils-2.13.90-20030111-1-src/configure --prefix=/usr/local/cross-tools --target=i386-mingw32msvc &> configure.log - Build and install binutils
This one is easy!After some long time, when its over do a cat make.log to make sure everything went ok. If yes all you need to do is:Code: Select all
make &>make.logAgain check the log file. If everything is OK you are on your way to go!Code: Select all
make install &>make_install.log - Export binutils path
Otherwise gcc won't be able to find it! I had some trouble with that...Code: Select all
export PATH=$PATH:/usr/local/cross-tools/bin - Configure gcc
Check the log to see if everything went ok.
Code: Select all
cd /root/croos/binutils-i386-mingw32msvc /root/cross/source/gcc-3.2.3-20030504-1/configure -v --prefix="/usr/local/cross-tools" --target=i386-mingw32msvc --with-headers="/usr/local/cross-tools/i386-mingw32msvc/include" --with-gnu-as --with-gnu-ld --without-newlib --disable-multilib &> configure.log - Build and install gcc
Don't forget to check the logs!
Code: Select all
make &> make.log make install &> make_install.log - Clean the sys-includes
These are used by the gcc build process and are not needed to compile anything else.Code: Select all
rm -rf "/usr/local/cross-tools/i386-mingw32msvc/sys-include
To compile:
Code: Select all
i386-mingw32msvc-gcc <source_name>.c -o <target_name>






