Free COMPILERS and CROSS-COMPILERS for LINUX and WINDOWS.

Here you can discuss ReactOS related topics.

Moderator: Moderator Team

Post Reply
JimGunn
Posts: 29
Joined: Sun May 25, 2008 6:04 am

Free COMPILERS and CROSS-COMPILERS for LINUX and WINDOWS.

Post by JimGunn »

Hi everyone. Some kind soul pointed me to this page.

It is very good. It cleared up many points for me.

So I had to share it with everyone.

Free Compilers and Cross-Compilers
for Linux and Windows.


http://linuxhelp.150m.com
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 will probably want the Eclipse Java compiler, so that gcj will be able to parse .java source files:

ecj-latest.jar from sourceware.org

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: Select all

mkdir /gcc; cd /gcc 
for a in *.tar.*; do tar xf $a; done 
(unpacks everything)

Code: Select all

mkdir binutils-linux-linux binutils-linux-win32 binutils-win32-win32 binutils-win32-linux 

Code: Select all

mv ecj-latest.jar /gcc/gcc-4.2.3/ecj.jar 
(needed to parse .java source files)

Code: Select all

cd /gcc/binutils-linux-linux 
/gcc/binutils-2.18.50/configure 
make 
make install 

Code: Select all

cd /gcc; mkdir gmp-linux gmp-win32 

Code: Select all

cd /gcc/gmp-linux 
/gcc/gmp-4.2.2/configure 
make 
make install 
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.

Code: Select all

ldconfig 

Code: Select all

cd /gcc; mkdir mpfr-linux mpfr-win32 

Code: Select all

cd /gcc/mpfr-linux 
/gcc/mpfr-2.3.1/configure 
make 
make install 
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.

Code: Select all

ldconfig 

Code: Select all

cd /gcc; mkdir gcc-linux-linux gcc-linux-win32 gcc-win32-win32 gcc-win32-linux 

Code: Select all

cd /gcc/gcc-linux-linux 
/gcc/gcc-4.2.3/configure --enable-languages=c,c++,fortran,java,objc,obj-c++,treelang 
make 
make install 
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:

Code: Select all

export PATH=/usr/local/bin:$PATH; echo $PATH 
(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.

Code: Select all

cd /gcc/binutils-linux-win32 
/gcc/binutils-2.18.50/configure --target=i686-pc-mingw32 
make 
make install 

Code: Select all

cp -r /gcc/{mingw-runtime-3.14,w32api-3.11}/include /usr/local/i686-pc-mingw32 
ln -s w32api-3.11 w32api 

Code: Select all

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: Select all

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: Select all

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 
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.

Code: Select all

rm -fr /gcc/gcc-linux-win32 
mkdir /gcc/gcc-linux-win32 
cd /gcc/gcc-linux-win32 

Code: Select all

/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 
Know you need to run ldconfig to tell all the other programs where to find the necessary libraries:

Code: Select all

ldconfig 
(4) Compile a C,C++,Java,Fortran,ObjC,ObjC++ compiler for Windows.

This compiler is a native Windows compiler. That is, it runs on a Windows box. It compiles Windows source code and the resulting binaries will run on Windows. When compiling C++, this compiler will do the same job as Visual C++ or C++ Builder.

Code: Select all

export CC="i686-pc-mingw32-gcc"; echo $CC 

Code: Select all

mkdir /mingw 
cp -r /usr/local/i686-pc-mingw32/{include,lib} /mingw 
The configure script expects to find the system headers and libraries in /mingw, so we have arranged for them to be there.

Code: Select all

cd /gcc/binutils-win32-win32 
/gcc/binutils-2.18.50/configure --build=i686-pc-linux-gnu \ 
            --host=i686-pc-mingw32 \ 
            --target=i686-pc-mingw32 \ 
            --prefix=/mingw 
make 
make install 

Code: Select all

cd /gcc/gmp-win32 
/gcc/gmp-4.2.2/configure --build=i686-pc-linux-gnu \ 
            --host=i686-pc-mingw32 \ 
            --prefix=/mingw 
make 
make install 

Code: Select all

cd /gcc/mpfr-win32 
/gcc/mpfr-2.3.1/configure --build=i686-pc-linux-gnu \ 
            --host=i686-pc-mingw32 \ 
            --prefix=/mingw 
make 
make install 
If you look inside the libtool libraries, i.e., the .la files, you will see they have their destination directory hard-coded into them, so they must be transfered to C:\mingw on your Windows box.

Code: Select all

cd /gcc/gcc-win32-win32 
/gcc/gcc-4.2.3/configure --build=i686-pc-linux-gnu \ 
            --target=i686-pc-mingw32 \ 
            --host=i686-pc-mingw32 \ 
            --enable-languages=c,c++,fortran,java,objc,obj-c++ \ 
            --prefix=/mingw 
make 
make install 
(5) Compile a C,C++,Java,Fortran cross-compiler for Windows.

This compiler runs on a Windows box. It compiles Windows source code and the resulting binaries will run unaltered on Linux. Ever wanted to compile VirtualDub so that it runs on Linux? This avoids having to port the source code.

Code: Select all

cd /gcc/binutils-win32-linux 
/gcc/binutils-2.18.50/configure --build=i686-pc-linux-gnu \ 
            --host=i686-pc-mingw32 \ 
            --target=i686-pc-linux-gnu \ 
            --prefix=/mingw 
make 
make install 

Code: Select all

cd /gcc/gcc-win32-linux 
/gcc/gcc-4.2.3/configure --build=i686-pc-linux-gnu \ 
            --host=i686-pc-mingw32 \ 
            --target=i686-pc-linux-gnu \ 
            --enable-languages=c,c++,fortran,java \ 
            --disable-libgomp \ 
            --prefix=/mingw 
make 
make install 
Now you copy everything in /mingw to C:\mingw on a Windows box and start compiling there. After you have compiled your Windows program, say VirtualDub, on your Windows computer, you transfer the resulting executable back to Linux and run it there. Of course, for most compilations you will also need to compile a version of the make program for Windows. You can compile the make program for Windows, on your Linux box, by using the cross-compiler you built in step (3).

(6) How to use the cross-compiler you built in step 3.

As a quick example of how to use the cross-compiler you built in step 3. Download the Linux make program to /gcc/:

make-3.81.tar.bz2 from www.gnu.org/

Code: Select all

export CC="i686-pc-mingw32-gcc"; echo $CC 
cd /gcc; tar xf make-3.81.tar.bz2; cd /gcc/make-3.81 
./configure --build=i686-pc-linux-gnu \ 
            --host=i686-pc-mingw32 \ 
            --prefix=/mingw 
make 
make install 
Now copy make.exe to C:\mingw\bin on your Windows box. Easy, isn't it?

(7) Adding the language ADA to the mix.

Download the following binary gnat package to /gcc/:

gnat-3.15p-i686-pc-redhat71-gnu-bin.tar.bz2 (12M) from linuxfromscratch.org

Code: Select all

tar xf gnat-3.15p-i686-pc-redhat71-gnu-bin.tar.bz2 
cd /gcc/gnat-3.15p-i686-pc-linux-gnu-bin/ 
Run the script doconfig entering /gcc/gnat for the installation directory. Then run doinstall.

Code: Select all

./doconfig; ./doinstall 
Follow the instructions of section (1), until the compilation of the compiler itself.

Then set your PATH variable so that you use the ADA-understanding compiler that you have just installed.

Code: Select all

export PATH=/gcc/gnat/bin:$PATH; echo $PATH 
Now compile the compiler of section (1), with one small change. Namely, add ada to the --enable-languages option.

Code: Select all

cd /gcc/gcc-linux-linux 
/gcc/gcc-4.2.3/configure \ 
            --enable-languages=c,ada,c++,fortran,java,objc,obj-c++,treelang 
make 
make install 
Then reset you PATH variable and continue from section (2), as above, except adding ada to the --enable-languages option.

Code: Select all

export PATH=/usr/local/bin:$PATH; echo $PATH 
You could also try the compiler in gnat-gpl-2007-i686-gnu-linux-libc2.3-bin.tar.gz (75M) from libre.adacore.com. Unfortunately, gcc-4.2.3 does not compile at all and gcc-4.3.0 does not compile outside the sources.

If at any time you need to know which compiler you are using, just enter the command:

Code: Select all

gcc -v 
Using built-in specs.
Target: i686-pc-linux-gnu
Configured with: /gcc/gcc-4.2.3/configure --enable-languages=c,ada,c++,fortran,java,objc,obj-c++,treelang
Thread model: posix
gcc version 4.2.3

The compiler in the gnat package is gcc version 2.8.1. Ancient, but worked like a charm.

(8) Using the Compiler you built in step 1.

The first thing to note, is that the "obvious"

Code: Select all

gcc program.f 
and

Code: Select all

gcc program.java 
do not work.

The Fortran front-end is gfortran. It is used as

Code: Select all

gfortran program.f 

Code: Select all

gcc -lgfortranbegin -lgfortran program.f 
also works.

The Java front-end is gcj. The following incantations can be used to compile Java code:

Code: Select all

gcj --main=program program.java 
(compile to C++ object file, a.out)

Code: Select all

./a.out 
(execute the C++ object file, a.out)

Code: Select all

gcj -C program.java 
(compile to Java bytecode file, program.class)

Code: Select all

gij program 
(execute the bytecode, program.class, with the GCC Java Virtual Machine)

To compile ObjC code, use

Code: Select all

gcc -lobjc program.m 
If you mix ObjC code and C++ code in the same files, you call the resulting mixture, ObjC++ code. It is apparently compiled in the same way as ObjC code. You are totally on your own for treelang.

To compile ADA code, use

Code: Select all

gnat make program.adb 
(9) General Remarks.

Since it is difficult to cut and paste many of the above commands, here is the script I used for the project.

If you are building on an older PC, replace i686 by i386, everywhere in the above.

For AMD-64, the script config.guess, gives x86_64-unknown-linux-gnu. It seems you can put any word in place of unknown, or no word at all. So configure with something like:

Code: Select all

./configure --build=x86_64-linux-gnu \ 
            --host=x86_64-linux-gnu \ 
            --target=i686-pc-mingw32 
I actually used x86_64-pc-linux-gnu and am assuming that x86_64-linux-gnu will work.

If you have a multilib system, like Debian, you may want to compile both 32-bit and 64-bit libraries for gcc. You need to have all the standard 32-bit libraries installed. On Debian, make sure you have the links:

Code: Select all

ln -s /lib /lib64 
ln -s /emul/ia32-linux/lib /lib32 
ln -s /usr/lib /usr/lib64 
ln -s /emul/ia32-linux/usr/lib /usr/lib32 
The compilation will fail, for gcc-4.2.3, unless you use the --disable-multilib configuration option, or you create the (secret) link:

Code: Select all

ln -s /emul/ia32-linux/lib /usr/local/x86_64-pc-linux-gnu/lib/32 
For gcc-4.3.0 the above link appears to be unnecessary (4.3.0 has other problems).

I have been running short on space and over time have deleted all my Windows partitions. As soon as I get around to reinstalling Windows, I will let you know how the Windows compilers work. I have now done this. There are weird problems with the Fortran compiler and the Java Virtual Machine, gij, is mysteriously missing. C C++ ObjC and ObjC++ seem OK, at least for simple programs. The compilers were run from an XP cmd window. I only looked at the native Windows compilers. I will look at the cross compilers at some later date.

By the way, if you wish to both watch, and record, the output of the compilation, you can do this:

Code: Select all

./configure 2>&1 | tee log.configure 
make 2>&1 | tee log.make 
make install 2>&1 | tee log.install 
If you have any suggestions or advice, please leave a note at:

http://www.phoronix.com/forums/showthread.php?t=8411
z180
Posts: 197
Joined: Sat Mar 10, 2007 7:58 pm

Re: Free COMPILERS and CROSS-COMPILERS for LINUX and WINDOWS.

Post by z180 »

This would fit into the tutorials froum.
Also please note that GCC developers already released the bugfix release 4.3.1
This release is not available from the MinGW32 page yet.
Haos
Test Team
Posts: 2954
Joined: Thu Mar 22, 2007 5:42 am
Contact:

Re: Free COMPILERS and CROSS-COMPILERS for LINUX and WINDOWS.

Post by Haos »

Does anyone have a list of fixed issues in 4.3.1?

EDIT: Nvm, i found it: http://gcc.gnu.org/bugzilla/buglist.cgi ... tone=4.3.1

I dunno if this one helps us in anything.
z180
Posts: 197
Joined: Sat Mar 10, 2007 7:58 pm

Re: Free COMPILERS and CROSS-COMPILERS for LINUX and WINDOWS.

Post by z180 »

I think that some brave one should risk it to compile reactos with 4.3.1.
Perhaps it would be better to wait for a mingw release of 4.3.1.
The ReactOS devs tried an alpha of 4.3.0 and it found bugs in the ReactOS code.
GCC 4.3.X has many improvements but also many problems.
Read the changelogs summaries and you will find useful changes.
JimGunn
Posts: 29
Joined: Sun May 25, 2008 6:04 am

Re: Free COMPILERS and CROSS-COMPILERS for LINUX and WINDOWS.

Post by JimGunn »

z180 wrote:I think that some brave one should risk it to compile reactos with 4.3.1.
Looks like http://linuxhelp.150m.com and http://linux.50webs.org

also have a page on GCC 4.3.0 (which is almost the same as 4.3.1) called

Free Compilers and Cross-Compilers for Linux and Windows. (GCC 4.3.0 Initial Results)

Apparently Java for Windows works better in 4.3.0 (maybe it doesn't work at all for 4.2.3, it's not that clearly stated).

And the Windows Cross-Compilers don't compile at all for 4.3.0, but do for 4.2.3.
JimGunn
Posts: 29
Joined: Sun May 25, 2008 6:04 am

Re: Free COMPILERS and CROSS-COMPILERS for LINUX and WINDOWS.

Post by JimGunn »

Has anyone here tried (and is thus able to report on) the above program.
Post Reply

Who is online

Users browsing this forum: No registered users and 57 guests