For compiling software you will need a few things. You will need the source code for the program that you are trying to compile. You will need a compiler that can create executables. And lastly in case of errors that you can't fix yourself, have the e-mail address of the author of the program or of the software company available. If that fails, turn to your favorite search engine, newsgroup, mailing list, or wherever else you go to get help.
On Solaris systems the two most popular compilers are:
SUN's C Compiler - cc is short for C compiler
GNU's C Compiler - GCC is short for GNU's Compiler Collection.
There are a few differences in these compilers.
In the past people would choose GCC over SUN's compilers simply because they couldn't afford to purchase SUN's compilers. SUN is now offering their compiler's without support for free so money is no longer a road block.
SUN's compilers come with a lot of goodies built in that GNU's does not. You can supplement GNU's compilers with other GNU software to achieve some of the same functionality but you have to assemble all of the pieces yourself.
The vast majority of open source software is probably written on a Linux system. Linux systems are built to use GCC and associated GNU software for their development environment. GNU sometimes add GNU extensions to commands and then the compiler environment expects to find these extensions to get the programs to compile.
Solaris started out as a System V variant and uses the old System V convention for thier binaries.
As such the GNU extensions are not available to stock Solaris commands.
This causes some open source projects to have problems compiling when you are using stock Solaris commands.
To get around this you need to install the GNU equivalent of that command and place it first in your PATH command. Then gcc will find the extension that it's expecting to find and the project will compile properly.
For instance older versions of Solaris commands such as tr or gettext would not work when compiling Gnome. The fix is to download and install a GNU version of tr and gettext and place those versions first in your PATH statement. Sun has taken the time to add some "GNUisms" to it's commands so this may no longer apply.
Another reason that SUN's compiler is considered superior to GNU's is that SUN's compilers are tightly coupled to the hardware and can take advantage of SUN's hardware in ways that GNU's doesn't.
GNU's compilers are designed to run a range of UNIX variants not just Solaris. Although there are some optimizations that you can enable in GNU's compiler for SUN hardware, SUN's compiler will probably always produce faster code than GNU's will. However, since SUN is now open sourcing their software and hardware GNU might be able to close the gap.
Older versions of Solaris did not come bundled with a compiler. In order to compile software on Solaris you needed to install either GNU's C Compiler or SUN's C Compiler. On the Solaris 10 DVD that I ordered from SUN gcc was just another option in the pick list of things that you could choose to install. This makes getting a compiler on the system extremely easy.
Be careful of which cluster you choose to install. When you install the Developer Cluster or greater of Solaris what you are actually installing are all of the utility software, libraries, and header files that the compiler uses to produce binary programs.
Installing the Developer Cluster or greater will put you in a position so that all you will need to do is to select to install gcc and adjust your PATH setting. After that you're ready to start compiling programs.
You don't need to install the Developer Cluster or greater to be able to compile software. According to Casper Dik's Solaris 2.x faq the packages you will need to insure that are installed on your system to compile software are:
for tools (sccs, lex, yacc, make, nm, truss, ld, as):
SUNWbtool, SUNWsprot, SUNWtoo, SUNWcpp
for libraries & headers:
SUNWhea, SUNWarc, SUNWlibm, SUNWlibms, SUNWdfbh, SUNWcg6h, SUNWxwinc,
SUNWolinc, SUNWxglh, SUNWlibC, SUNWzlib, SUNWscpu
for 64 bit development:
SUNWarcx, SUNWbtoox, SUNWdplx, SUNWscpux, SUNWsprox, SUNWtoox, SUNWlmsx,
SUNWlmx, SUNWlibCx, SUNWzlibx
for ucb compat:
SUNWsra, SUNWsrh
These packages are all on the Solaris 2.x CDs except that some packages may only exist in some releases and not in others. Some packages may be on separate CDs, such as the "Desktop/CDE" CD, but all are part of the Solaris "bundle".
Some of the above packages do not exist in all Solaris releases.
If you're using OpenSolaris 200805 then use the following commands:
pkg install gcc-dev for GCC
pkg install ss-dev for Sun Studio Express
In the old days it was advisable to only use Sun's version of as or ld. As you will see later on this has changed.
All the binaries live in /usr/ccs/bin. Make sure that this is present in your PATH before you attempt to compile software.
The first thing you should do if you are going to use GNU's compiler is to compile your own compiler. If you are going to use SUN's compiler read through the included docs and you're on your way. Using SUN's compilers will not be covered here.
We are going to go through the steps to compile GCC on your computer. The steps to compile any other program will be pretty much the same.
It's important to remember that you don't need to install a compiler on all of your computers. If you have several SUN 4U architecture machines then one machine can compile source code for all of your SUN 4U machines. After you compile the code you can create a package and then use ftp or whatever other means are available to push the code out to other machines. To check your machine type use the uname command.
You also need to be aware of which version of Solaris you're running. If your compiler sits on a machine running Solaris version 8 you probably won't be able to run this code on an earlier version of Solaris. Your compiled code should run on later revisions of Solaris code. This is because SUN is constantly adding things to the OS and what exists in the existing version of Solaris may or may not be available on an earlier revision.
Ok, so how do you go about compiling your own GNU compiler? It's not very hard.
First, on the machine that you're going to use to compile software insure that the packages listed above are installed. Second, modify your PATH to include /usr/ccs/bin. /usr/ccs/bin only covers the stock Solaris utilities and does not cover the path that gcc needs.
Install gcc. Be sure to note which directory that the files are being created in. You'll need to add this to your PATH statement. If you aren't sure what directory gcc is in then you could use the find command to find gcc and then add that directory to your PATH statement. If you did what I did and just picked gcc out of the pick list then add /usr/sfw/bin to your PATH statement.
After you've installed the package and modified your PATH, then the command, gcc --version, should return the version of gcc that you've just installed on your system.
You are now ready to compile your own compiler.
You will need to ftp the current version of gcc from ftp://ftp.gnu.org/gnu/gcc.
Before you compile GCC you should take the time to setup some other environment variables.
Next Section: Environment Variables (3 of 11)