<--Last Chapter | Table of Contents | Next Chapter--> |
Gnat is a part of the gcc project. The gcc command itself isn't a
compiler: it's a program that determines the kind of source file
you have and runs the appropriate compiler for you. For example,
the Ada compiler is called gnat1
, and the C compiler
is called cc1
. When gcc detects an Ada source file, it
runs gnat1 to compile it.
Because gcc and Gnat must work as a team, specific versions of Gnat are created for specific versions of gcc. Gnat 3.10p is compiled against the gcc for kernel 2.0.29 (for example, the version of gcc used in the Slackware 3.2 distribution). Gnat 3.11p, 3.12p and 3.13p are compiled against gcc 2.8.1.
To find out which version of gcc you have, run gcc with the -v switch. |
It is possible to install one version of gcc overtop of another and to select one version or the other using the gcc -V switch, but gcc must again be recompiled from its (newest) sources to make it aware of the other version. |
Recently, the chief ALT maintainer has moved onto other interests and the ALT web site is out-of-date. Due to Gnat's integration into Gcc 3.x, there has been less interested in Gnat RPMS. However, there are still RPMs around hosted by other people (and usually based on the ALT system). Check out other sites such as ftp.ada95.com/pub/gnat-3.14p/RH-7/ or http://prdownloads.sourceforge.net/gnuada/.
The ALT versions include support for ASIS, GLADE and native Linux threads. The package includes gnatgcc, a version of gcc with Gnat and C++ support, and gnatgdb, a version of gdb that supports Ada source code, plus gnatprep and the other Gnat utilities.
The rpm files are built for Red Hat and S.u.S.E. distributions. If you try installing it on another distribution, use --nodep to ignore any package dependency warnings. |
RPMS for Version 3.15p for Red Hat 7.2 are available at http://www.alex.wubn.net/packages/3.15p/RPMS and http://www.alex.wubn.net/packages/3.15p/SRPMS.
The ALT GNAT build system is available for those wanting to know more about how the RPMs are constructed. Using CVS, you can check our the source code.
export CVSROOT=":pserver:anoncvs@hornet.rus.uni-stuttgart.de:/var/cvs" cd $HOME cvs login # (use empty password) cvs -z9 co -d ALT gnuada/alt-build
The latest version of the Gnat compiler is available from the ACT FTP site. These binaries do not have the extra features available with the ALT RPMs, but they include extra installation information, including how to install Gnat's various add-ons. There are also versions for other operating systems besides Linux.
Gnat 3.12 and older have an additional install option to overwrite you're existing copy of gcc, provided it is right version. Since it is rare that a distribution has the exact same version of gcc, this option is no longer provided. |
ACT will sometimes release several versions of Gnat for different C libraries. When downloading the binaries, make sure that you download the version compiled against the appropriate C library. This is due to the constantly evolving nature of Linux.
To find out which libc library your distribution uses, examine the /lib/libc.so link to find out which file it points to. For example, if /lib/libc.so points to a libc5 library, then you'll need the libc5 version. |
By default, Gnat is installed in a /usr/gnat subdirectory.
If you don't have gcc 2.8.1, you can specify a separate directory where gnat will install itself and its own personal copy of gcc 2.8.1. Using this method, you need to perform an additional step. The installation program (doconfig) creates a shell script containing environment variables that you can copy to your shell startup script (under bash, this is usually the .profile file in your home directory). Gcc uses these variables to locate the gnat files.
You will need to include the gnat directory in the front of your PATH variable to prevent gnat from using the gcc that came with your Linux distribution. For example, use the shell command:
export PATH="/usr/gnat/bin:$PATH"
Only use this command when you want to use Gnat since it effectively hides the copy of gcc that came with your distribution.
If you don't want gnat to be enabled by default, you can write a short shell script that assigns the environment variables, sets the path, and starts a new shell.
As of GCC 3.1, GNAT 5.x is included with the GCC sources. Because this is the first version of GNAT designed for compatibility with the latest GCC releases, GNAT 5.x is officially a "test version" with known bugs. (Previous versions of GNAT were "hard-coded" and tested for particular GCC releases.)
The latest GCC build instructions are at http://gcc.gnu.org/install/
We tried to build GCC 3.2 with Ada on Red Hat 7.1 and a Pentium II.
$ ls -l gcc-3.2.tar.bz2 -rwxr-xr-x 1 root root 20523950 Aug 21 19:39 gcc-3.2-tar.bz2
$ tar xfvj gcc-3.2.tar.bz2
cd objdir mkdir libiberty cd libiberty ./../libiberty/configure .... make
$ nice ../gcc-3.2/configure Configuring for a i686-pc-linux-gnu host
$ rpm -q binutils binutils-2.11.90.0.8-9
$ nice makeThis step takes the most time. GCC will need to build all the languages three times. These are called the stage1, stage2 and stage3 compilers.
$ cd ../gcc-3.2/gcc/ada $ touch treprts.ads [es]info.h nmake.ad[bs] $ cd ../../../objdir/gcc $ make gnatlib_and_tools $ cd ..It may be a good idea to use "LD_ASSUME_KERNEL=2.2.5" or "LD_ASSUME_KERNEL=2.4.1"...this affects the thread support.
$ make install
In order to recompile Gnat 3.x, you'll need the following:
First, you need to recompile the gcc compiler. Make sure you follow gcc's instructions for activating Ada support.
make CFLAGS="-g -fsigned-char" LANGUAGES="c c++ ada" make stage1 make CC="stage1/xgcc -Bstage1/" CC="-g -O2 -fsigned-char" STAGE_PREFIX="stage1/" LANGUAGES="c c++ ada" <build tools and lib with CC="./xgcc -B./">There are two problems that can arise:
Upgrading gcc to a new version of gcc, however, can be difficult. Gnat's gcc patches are designed for a specific version of gcc. It is usually a good idea to get a copy of the source code for the version of gcc Gnat was designed for and compile a second gcc compiler just for use with Gnat. For gnat 3.13, you'll need the gcc 2.8.1 source code. You should be able to compile an older version of gcc to work with newer C libraries, provided the compiler is only a few months out of date.
Now follow the directions to compile Gnat. Make sure libgnat.a is accessible to the linker. If it isn't, copy it to /usr/lib and run ldconfig to update Linux's shared library tables.
We first went to the Sunsite mirror which provides Linux compiled binaries of gcc, ready to be unpacked and installed Unfortunately, the readme file reported they had trouble compiling gcc and supplied egcs instead. egcs is based on gcc 2.8.0 which meant that we couldn't use it with gnat 3.11. Instead we downloaded the gcc 2.8.1 source code from a GNU FTP mirror site and prepared to build the compiler from scratch.
doconfig
program and select option 1.
The gcc path that it's expecting is displayed as
i686-pc-linux-gnu
. This was going to be our configuration
host setting for gcc.
configure --with-gnu-as --with-gnu-ld --enable-threads=posix --host
i686-pc-linux-gnu
i686-pc-linux-gnu
was reasonable. It required lib6 and lib6
was installed. The Makefile also showed that the i686 setting is
compatible with our Pentium (i586).cc
to /usr/bin/gcc.
There was a cpp
syntax error while building libgcc1.a
, probably the
error the Slackware people encountered. We tracked down the line
causing the problem in the Makefile and discovered they were
calling cc to do the compiling, which doesn't handle the C
preprocessor (cpp) properly. Typing in the line at the shell prompt
showed that /usr/bin/gcc worked fine while /usr/bin/cc would not.
The note in the Makefile said we shouldn't use gcc to avoid
circular references in some of the functions (that is, that it
might inadvertantly call the 2.8.1 compiler instead of the old
2.7.2.3 compiler), so we made sure we included the full path.make LANGUAGES="c c++"
mkdir stage1; make stage1
make CC="stage1/xgcc -Bstage1/" CFLAGS="-g -O2
-fsigned-char"
mkdir stage2; make stage2
make CC="stage2/xgcc -Bstage2/" CFLAGS="-g -O2
-fsigned-char"
make compare
reported no errors.make install CC="stage2/xgcc" -Bstage2/" CFLAGS="-g -O2"
LANGUAGES="c c++"
gcc -v and gcc -dumpversion
reported
the correct version. We deleted the old
/usr/lib/gcc-lib/i486-linux
directory to save some
space.If we were doing C++ programming, we would need to install the standard C++ library, libstdc++, as well. In this case, we enabled C++ support to avoid recompiling gcc for C++ in the future.
Although this is a Linux book, here's some tips for Windows users:
Most Gcc uses use the Cygwin system which has a POSIX-compliant run-time system. This makes it easier to port and run programs from UNIX-like systems, including Linux. However, Gnat is based on Mingw and it uses the msvcrt runtime. (The reason for Mingw is, apparently, a problem with the Cygwin licensing agreement.) Unfortunately, because they have different run-time systems, Cygwin and Mingw are not compatible with one another.
If you want to build it on windows, you'll need the Mingw compiler. Try http://www.mingw.org/download.shtml" and look for the "experimental/test packages" section. If you have Cygwin and want it to use Gnat at the same time, you'll modify the registry entries for Gnat and replace GCC for GNAT_GCC in key names/values. If you're willing to use the Mingwin version of Gcc for your C programs, put the Gnat/Mingwin path ahead of the Cygwin path in your environment PATH variable.
For those simply looking for a compiler to run at the DOS prompt, DJGPP (the Gcc for MS-DOS project) supports recent versions of Gnat.
ACT sells commerical support for Gnat on VxWorks, the Windows emulator for Linux.
<--Last Chapter | Table of Contents | Next Chapter--> |