Three days ago I decided to look at cross compiling c++ on Windows. As I program mainly on Windows. It seemed logical to stay on Windows.
Otherwise, I would have had to switch between two operating system, Windows and Linux.
Today I am done.
I compiled my program and it runs under Linux. It is slight errors but in overall , it is ok.
I used crosstool (http://kegel.com/crosstool/). That program was made for cross-compiling easily in theory. It should be fully automatic.It did download all packages needed properly but I found some bugs that slowed down the process.
It took a long time because the compilation went for at least 6 hours before encountering an error. I have got AMD 2800+ and I Gigabyte computer.
I used Cygwin as my Unix-like environment. I chose it because it had an easy-to use setup/install program. As it turned out I needed it.
Here it is how I used the cross-tool.
First I edited demo-i686.sh. to set the location of the cross compiler. (for me , it was RESULT_TOP=/cygdrive/d/gcc/crosstoollinux)
In Cygwin command line, I ran ./demo-i686.sh. This is the one that produces the cross compiler for linux binaries on Windows. It can be used as it is but it does not contain an example for the most recent gcc/libs.
In demo-i686.sh, a line is usually like this...
eval `cat i686.dat gcc-4.1.0-glibc-2.3.6-tls.dat` sh all.sh --notest
(I found a useful option --nounpack to be added at the end of that line if one downloaded all packages that was required to build the libraries and cross-compiler.)
To build an up-to-date compiler, at this moment,
one should have eval `cat i686.dat gcc-4.1.1-glibc-2.4-tls.dat` sh all.sh --notest
Now about the bugs..
It turned out flex and bison had to be installed on Cygwin, otherwise the building stopped.
After running for a long time, the compilation ended with a weird error:
mv:makefile.tem cannot move to makefile, permission died.
Then I typed make in the command line to reproduce the error but then it disappeared.
The compilation also failed because it could not find "ar".
I added the directory of ar to the path.
I typed PATH=/cygdrive/d/gcc/crosstoollinux/gcc-4.1.1-glibc-2.3.6/i686-un
That was enough. Fortunately , that error came at the end of the building process.
That is ,in buildgcc directory.
This meant I just had to go back to buildgcc directory and type make and then make install and I finished.
Last problem I had how to run this compiler from a batch file.
The solution is:
c:\cygwin\bin\bash.exe -l -c "D:/gcc/crosstoollinux/gcc-4.1.1-glibc-2.3.6/i686-unknown-linux-gnu/i686-unknown-linux-gnu/bin/g++.exe -s -O2 -o binname..."
I found a website where one can download prebuilt binary. So it is possible to avoid the long build times.. (more than 6 hours)...
Its address is: link