I tried to compile some C code to get object file from a shell prompt:
But this gives me the following error:
/usr/ucb/cc: language optional software package not installed
How can I compile C code?
First, you should probably remove /usr/ucb from your PATH as this directory is quite obsolete now. It was meant to ease people migrating from SunOS 4 to Solaris 2 a couple of decades ago but doesn't make much sense these days. Especially this cc commands which set specific flags to compile BSDish code.
Second, all current Solaris releases comes with a C compiler out of the box but it is located in a directory which might not be in your PATH, /usr/sfw/bin and is named gcc (Gnu compiler).
Alternatively, you might have already installed (or you can install) the Solaris Studio compiler. In that case, its path would be <installation-dir>/bin/cc (eg: /opt/SUNWspro/bin/cc or /opt/SolarisStudio11/bin/cc etc ...)
Many times it's worth it to put strange error messages regarding compiling through Google. When I did this, it seems Solaris doesn't come with a compiler out of the box and that is why you are seeing this. I'm not familiar with Solaris at all, but maybe you need to use its package management tools or something similar to actually install the compiler if this is the case.
Your Solaris installation doesn't have a compiler installed. Back in the 1900:s, Sun charged extra for their C compiler, and provided a stub "cc" command instead, just to remind you that the compiler is not installed.
To compile a file, you need to install a compiler for the same Solaris version (2.5.1?) and architecture (SPARC/sun4m?) that matches your operating system and computer hardware.
Read more at SunFreeware.com for free software that installs under /usr/local/.
If you take that open source/GNU road, you will probably need to install a lot of packages to satisfy dependencies before it works, but if you have the disk space it would probably be worth it.
Old versions of Sun's SparCompiler/Forte/SunStudio can be hard to obtain for your (supposedly) old machine, as they were typically licensed with node locked licenses, and you will not be able to buy a license for those obsoleted software packages any more.