My knowledge of compilers is not that extensive and my knowledge of cross-compiling, even less.
My first question is: How much of the following article is "the way" it should be done?
Second question: What extra steps do you need to take to successfully cross-compile? For example:
Do you need extra DirectX libraries? Where do you get them from?
Free Compilers and Cross-Compilers
for Linux and Windows.
From http://linuxhelp.150m.com/
and http://linux.50webs.org
Yesterday's release of gcc, version 4.3.0, was a shock. The compilation of the Fortran compiler failed. The compilation of the Win32 (mingw32) cross compiler failed. This was incredibly shoddy for a major release. I imagined people having significant problems figuring what was going on, so, I wrote this article to try and help out. Of course, in this article, I will not use version 4.3.0, but its immediate predecessor, version 4.2.3.
Well, it turns out that both of these problems go away, if you do the build in directories separate from the sources. Since this is non-traditional, it might have been nice for people to point out that the build will not work, in certain cases, unless you build in separate directories. For projects like gcc, compiling in separate directories is actually a great idea.
Although the original problems with 4.3.0 have been solved, I ran into more difficulties later in the program, so, at least for the time being, I have stuck with version 4.2.3. Below, I have repeated the original program using separate build directories. If you do this, all the compilers and cross-compilers, are able to compile, at least, C, C++, Fortran and Java code. I made no attempt to incorporate ADA into the mix.
This is an outline of what we will do:
(1) compile a C,C++,Java,Fortran,ObjC,ObjC++,treelang compiler for Linux
(2) compile a C cross-compiler for Linux (needed to compile system libraries)
(3) compile a C,C++,Java,Fortran,ObjC,ObjC++ cross-compiler for Linux
(4) compile a C,C++,Java,Fortran,ObjC,ObjC++ compiler for Windows
(5) compile a C,C++,Java,Fortran cross-compiler for Windows
Compiler (1) runs on a Linux box and produces binaries that will run under Linux
Compiler (3) runs on a Linux box and produces binaries that will run under Windows
Compiler (4) runs on a Windows box and produces binaries that will run under Windows
Compiler (5) runs on a Windows box and produces binaries that will run under Linux
I have recently added some extra sections:
(6) How to use the Cross-Compiler(s) you built in step 3.
(7) Adding the language ADA to the mix.
(8) Using the Compiler(s) you built in step 1.
(9) General Remarks.
Make sure that you have the following programs and packages installed.
For SuSE 10.0: gcc libgcc glibc glibc-devel glib2 glib2-devel ncurses ncurses-devel gcc-c++ libstdc++ libstdc++-devel.
For Debian: emacs21 bzip2 gcc libncurses5-dev libc6-dev libc6-dev-i386 lib32gcc1 g++ libstdc++6-4.1-dev (and gnat if you want ADA).
You may also need to install autoconf and automake.
You will need at least 5 Gigabytes of free space. The compilation of part (1) took nearly 4 hours. The rest took just under 2 hours.
Download the following to the directory /gcc/:
binutils-2.18.50.tar.bz2 (16M)
gcc-4.2.3.tar.bz2 (43M) from www.gnu.org/
You can also obtain gcc-4.2.3.tar.bz2 in smaller pieces. Note, that in order to compile the ADA compiler, you need a working ADA compiler (GNAT 3.14, or later) on your system.
You need the following Win32 API and runtime files:
w32api-3.11-src.tar.gz
mingw-runtime-3.14-src.tar.gz from www.mingw.org
By the way, mingw.org exists to mislead and hinder, rather than help.
It is best to upgrade your version of gmp and mpfr:
mpfr-2.3.1.tar.bz2 from www.mpfr.org
gmp-4.2.2.tar.bz2 from gmplib.org
It is assumed that you are the root user.
(1) Compile a C,C++,Java,Fortran,ObjC,ObjC++,treelang compiler for Linux.
We do this to have an up-to-date compiler (actually, a collection of compilers) with which to compile the cross-compilers of steps 2 and 3. Beginning with an older compiler can lead to some complications. I did the build on a SuSE 10.0 Linux box. Using the installed compiler (version 4.0.2) worked for all steps except parts of (4) and all of (5). Using version 4.2.3 means that most things work.
Save all the packages to the directory /gcc/. Go there and unpack everything:
(unpacks everything)
The make install script runs the command ldconfig -n /usr/local/lib. It turns out that this is not sufficient, you need to run ldconfig (as root). This updates the ld.so.cache file so that it knows to use the newly installed gmp library, rather than some older, pre-existing, gmp library. In particular, you want the compilation of the mpfr library to use the correct version of gmp.
Similarly, if you have some pre-existing version of the mpfr library, then you need to run ldconfig again. You should probably run ldconfig again, in any case, just to be on the safe side.
So that version 4.2.3 does not interfere with your older installed compiler, it will be installed in /usr/local/. To use it, instead of the installed compiler, you need to have /usr/local/bin first on your path. You arrange this with:
(2) Compile a C cross-compiler for Linux.
This C cross-compiler will run on your Linux system and create binaries, from Linux C code, that will run on a Windows system. We need to use this cross-compiler to compile the Win32 API and runtime libraries.
The files in /usr/local/i686-pc-mingw32, will be used for cross-compiling Linux programs to run on Windows.
(3) Compile a C,C++,Java,Fortran,ObjC,ObjC++ cross-compiler for Linux.
The C cross-compiler is compiled again, along with the other languages. This cross-compiler is run on your Linux box and compiles binaries, from Linux code, that will run on a Windows system. That is, it compiles Linux source code, so that the resulting binaries will run, unaltered, on Windows.
Know you need to run ldconfig to tell all the other programs where to find the necessary libraries:
My first question is: How much of the following article is "the way" it should be done?
Second question: What extra steps do you need to take to successfully cross-compile? For example:
Do you need extra DirectX libraries? Where do you get them from?
Free Compilers and Cross-Compilers
for Linux and Windows.
From http://linuxhelp.150m.com/
and http://linux.50webs.org
Yesterday's release of gcc, version 4.3.0, was a shock. The compilation of the Fortran compiler failed. The compilation of the Win32 (mingw32) cross compiler failed. This was incredibly shoddy for a major release. I imagined people having significant problems figuring what was going on, so, I wrote this article to try and help out. Of course, in this article, I will not use version 4.3.0, but its immediate predecessor, version 4.2.3.
Well, it turns out that both of these problems go away, if you do the build in directories separate from the sources. Since this is non-traditional, it might have been nice for people to point out that the build will not work, in certain cases, unless you build in separate directories. For projects like gcc, compiling in separate directories is actually a great idea.
Although the original problems with 4.3.0 have been solved, I ran into more difficulties later in the program, so, at least for the time being, I have stuck with version 4.2.3. Below, I have repeated the original program using separate build directories. If you do this, all the compilers and cross-compilers, are able to compile, at least, C, C++, Fortran and Java code. I made no attempt to incorporate ADA into the mix.
This is an outline of what we will do:
(1) compile a C,C++,Java,Fortran,ObjC,ObjC++,treelang compiler for Linux
(2) compile a C cross-compiler for Linux (needed to compile system libraries)
(3) compile a C,C++,Java,Fortran,ObjC,ObjC++ cross-compiler for Linux
(4) compile a C,C++,Java,Fortran,ObjC,ObjC++ compiler for Windows
(5) compile a C,C++,Java,Fortran cross-compiler for Windows
Compiler (1) runs on a Linux box and produces binaries that will run under Linux
Compiler (3) runs on a Linux box and produces binaries that will run under Windows
Compiler (4) runs on a Windows box and produces binaries that will run under Windows
Compiler (5) runs on a Windows box and produces binaries that will run under Linux
I have recently added some extra sections:
(6) How to use the Cross-Compiler(s) you built in step 3.
(7) Adding the language ADA to the mix.
(8) Using the Compiler(s) you built in step 1.
(9) General Remarks.
Make sure that you have the following programs and packages installed.
For SuSE 10.0: gcc libgcc glibc glibc-devel glib2 glib2-devel ncurses ncurses-devel gcc-c++ libstdc++ libstdc++-devel.
For Debian: emacs21 bzip2 gcc libncurses5-dev libc6-dev libc6-dev-i386 lib32gcc1 g++ libstdc++6-4.1-dev (and gnat if you want ADA).
You may also need to install autoconf and automake.
You will need at least 5 Gigabytes of free space. The compilation of part (1) took nearly 4 hours. The rest took just under 2 hours.
Download the following to the directory /gcc/:
binutils-2.18.50.tar.bz2 (16M)
gcc-4.2.3.tar.bz2 (43M) from www.gnu.org/
You can also obtain gcc-4.2.3.tar.bz2 in smaller pieces. Note, that in order to compile the ADA compiler, you need a working ADA compiler (GNAT 3.14, or later) on your system.
You need the following Win32 API and runtime files:
w32api-3.11-src.tar.gz
mingw-runtime-3.14-src.tar.gz from www.mingw.org
By the way, mingw.org exists to mislead and hinder, rather than help.
It is best to upgrade your version of gmp and mpfr:
mpfr-2.3.1.tar.bz2 from www.mpfr.org
gmp-4.2.2.tar.bz2 from gmplib.org
It is assumed that you are the root user.
(1) Compile a C,C++,Java,Fortran,ObjC,ObjC++,treelang compiler for Linux.
We do this to have an up-to-date compiler (actually, a collection of compilers) with which to compile the cross-compilers of steps 2 and 3. Beginning with an older compiler can lead to some complications. I did the build on a SuSE 10.0 Linux box. Using the installed compiler (version 4.0.2) worked for all steps except parts of (4) and all of (5). Using version 4.2.3 means that most things work.
Save all the packages to the directory /gcc/. Go there and unpack everything:
Code:
mkdir /gcc; cd /gcc for a in *.tar.*; do tar xf $a; done
Code:
mkdir binutils-linux-linux binutils-linux-win32 binutils-win32-win32 binutils-win32-linux
Code:
cd /gcc/binutils-linux-linux /gcc/binutils-2.18.50/configure make make install
Code:
cd /gcc; mkdir gmp-linux gmp-win32
Code:
cd /gcc/gmp-linux /gcc/gmp-4.2.2/configure make make install
Code:
ldconfig
Code:
cd /gcc; mkdir mpfr-linux mpfr-win32
Code:
cd /gcc/mpfr-linux /gcc/mpfr-2.3.1/configure make make install
Code:
ldconfig
Code:
cd /gcc; mkdir gcc-linux-linux gcc-linux-win32 gcc-win32-win32 gcc-win32-linux
Code:
cd /gcc/gcc-linux-linux /gcc/gcc-4.2.3/configure --enable-languages=c,c++,fortran,java,objc,obj-c++,treelang make make install
Code:
export PATH=/usr/local/bin:$PATH; echo $PATH
This C cross-compiler will run on your Linux system and create binaries, from Linux C code, that will run on a Windows system. We need to use this cross-compiler to compile the Win32 API and runtime libraries.
Code:
cd /gcc/binutils-linux-win32 /gcc/binutils-2.18.50/configure --target=i686-pc-mingw32 make make install
Code:
cp -r /gcc/{mingw-runtime-3.14,w32api-3.11}/include /usr/local/i686-pc-mingw32 ln -s w32api-3.11 w32api
Code:
cd /gcc/gcc-linux-win32/ /gcc/gcc-4.2.3/configure --target=i686-pc-mingw32 \ --with-headers=/usr/local/i686-pc-mingw32/include \ --enable-languages=c make make install
Code:
cd /gcc/w32api-3.11 ./configure --build=i686-pc-linux-gnu \ --host=i686-pc-mingw32 \ --prefix=/usr/local/i686-pc-mingw32 make make install
Code:
cd /gcc/mingw-runtime-3.14 ./configure --build=i686-pc-linux-gnu \ --host=i686-pc-mingw32 \ --prefix=/usr/local/i686-pc-mingw32 make make install
(3) Compile a C,C++,Java,Fortran,ObjC,ObjC++ cross-compiler for Linux.
The C cross-compiler is compiled again, along with the other languages. This cross-compiler is run on your Linux box and compiles binaries, from Linux code, that will run on a Windows system. That is, it compiles Linux source code, so that the resulting binaries will run, unaltered, on Windows.
Code:
rm -fr /gcc/gcc-linux-win32 mkdir /gcc/gcc-linux-win32 cd /gcc/gcc-linux-win32
Code:
/gcc/gcc-4.2.3/configure --target=i686-pc-mingw32 \ --with-headers=/usr/local/i686-pc-mingw32/include \ --enable-languages=c,c++,fortran,java,objc,obj-c++ make make install
Code:
ldconfig
Comment