Building GCC

Last modified: Wed Jun 9 16:15:14 EDT 1999

Grab the freebie

Solaris doesn't come with a C compiler. You can either pay for their C development environment, or you can use the highly respectable GNU C compiler. This is what everyone does, just about. Problem: how do you compile a compiler if you don't have a compiler to begin with? Solution: write your own using lexx and yacc (yet another compiler compiler) and a lot of coding, or somehow 'bootstrap' your compiler by getting a binary version of a compiler. Use this compiler to build your own.

You can grab a solaris packagized version of the GNU compiler at This pointed to the FTP site at, so the link to gcc was at

NOTE: you will have to have 'gzip' installed to read this package, or grab the gzip binary package, which conveniently is NOT gzipped, and use this to gunzip the gcc package.

If you use Netscape to pull down the gzip package, you may have to do a shift-right-click to 'Save as...' the distribution to disk. Otherwise, just use command line anonymous ftp. If you are unfamiliar with anonymous ftp, ask.

Install the gcc binary package

Once unzipped, you can add the package with the command:

pkgadd -d gzip-1.2.4-sol7-sparc-local

Now grab the source code for GCC

You can get this from GNU or their FTP site. At the time of writing this, the link for gcc was

Move this file to a the /usr/local/src directory and extract it it to a build directory. I recommend /usr/local/build.

cd /usr/local/build gzip -dc ../src/gcc-2.8.1.tar.gz | tar xf -

Then cd gcc-2.8.1 and get ready to build.

Get ready to configure

All you really need to do is read the README and the INSTALL file and you should be able to install gcc. Check your PATH variable (echo $PATH) to make sure that you have /usr/bin before /usr/ucb in your path, and also that do have what meagre development tools that sun provides in your PATH. You'll probably have to add /usr/ccs/bin (to get ar, make, etc.), and maybe /usr/ccs/lib (to get cpp). I do it like this:

export PATH

Then again, I use /bin/sh or bash. If you use C shell, do it like set path=(/usr/ccs/bin /usr/ccs/lib $PATH) or something like that.

Once you PATH is set, run configure, then run make. By default, it will go int /usr/local, which is probably right.

make stage1
make CC="stage1/xgcc -Bstage1/" CFLAGS="-g -O2"

Again, see the INSTALL file for details and what this really means. Basically, you are building a stage 2 compiler from a stage 1 compiler compiled with the preexisting binary compilers you pulled off the net.

Install it

BECOME ROOT! This step requires you to right to directories under /usr/local, which should only be writable by root.

su root
make install CC="stage2/xgcc -Bstage2/" CFLAGS="-g -O"
Add a comment | Add a link