Introduction
Since the availability of the Solaris 10 Operating System in January 2005, its popularity (using the number of registered users as a yardstick) has exploded: As of August 2006, in excess of 5 million copies were registered, more than all of the previous versions of the Solaris OS combined. Further fueling this frenzy was the release of OpenSolaris in June 2005. Given this surge in the number of users, more developers (commercial and open-source alike) are seeing the Solaris platform as a viable target for their software. This article explains why developers should make Solaris their primary development and deployment platform, and also explains how to develop software on the Solaris OS. This article assumes that C will be used as the programming language of choice, although much of the information is relevant to other high-level languages. The discussion is aimed at two kinds of people:
The article also assumes the use of the Solaris 10 (or newer) release, although most of it is relevant to previous versions. Why Develop on the Solaris Platform?
One of the reasons the Solaris OS enjoyed a huge popularity boost was its price: $0 for everyone, for any use (commercial and non-commercial), on any machine (using both SPARC and x86 platforms). Another reason was Sun's promise (and delivering on that promise) of making the Solaris source code available under an OSI-approved open-source license, the CDDL. However, the most important reason for the popularity of the Solaris OS is arguably the vast wealth of features it offers. In no particular order, these include Solaris Zones (the ability to partition a machine into numerous virtual machines, each of which is isolated from the others), DTrace (a comprehensive dynamic tracing tool for investigating system behavior, safely on production machines), a new IP stack with vastly increased performance, and most recently, ZFS (a 128-bit, state-of-the-art file system, with end-to-end error checking and correction, a simple command-line interface, and virtually limitless storage capacity). All these features build on what long-time Solaris OS users have come to expect: rock-solid stability, huge scalability, high performance, and guaranteed backwards compatibility. The last of these is especially important to commercial software developers, because maintenance is usually the largest expense associated with a piece of software. With its backwards compatibility guarantee, software vendors know that (provided they stick to published APIs) software built for Solaris N will run correctly on Solaris N+1 and subsequent versions. (Contrast this with some other operating systems, where incompatible changes to system components -- for example, libraries -- are made without regard to the effect on applications. The net effect is application breakage, resulting in increased maintenance costs and frustration for application vendors and users.) The preceding paragraphs give some reasons why we should develop for the Solaris OS, but there are additional reasons to develop on the Solaris platform. One is that Solaris is a multiplatform OS, supporting both SPARC and x86 architectures (a community-driven port to Power is in the works, too). Although there was a hiccup a few years ago with the Solaris OS for x86 platforms, the fact that Sun has introduced a range of AMD-based servers and workstations demonstrates the company's commitment to x86 technology. From the developer's perspective, the Solaris versions for SPARC and x86 platforms have the same feature set and APIs. This means that developers can concentrate on the other issues endemic to cross-platform development, like CPU endianness. The SPARC platform is big-endian and x86 is little-endian, so an application that is developed and tested on the Solaris platform has a high probability of being free from endian-related problems. The Solaris OS also supports both 32-bit and 64-bit applications on both platforms, thus helping to eliminate bugs due to assumptions about word size and so on. Perhaps the most compelling reason to develop software on the Solaris OS is the wealth of professional-grade development tools available for it. Development Tools on the Solaris Platform
Market-size issues aside, one of the most important features of an OS from a developer's point of view is the variety and quality of the development tools available. Compilers and debuggers are the most obvious examples of these tools, but other examples include code checkers (to ensure that our code is free from subtle errors the compiler might not catch), cross-reference generators (to see which functions reference other functions and variables), performance analyzers, and so on.
The Sun Studio 11 suite is the product of choice for Solaris OS developers. Available as a free download from the developers.sun.com, Studio 11 software is a collection of professional-grade compilers and tools. It includes C, C++, and FORTRAN compilers, code analysis tools, an integrated development environment (IDE), the
Other tools included with Studio 11 software are
The Solaris OS ships with the GNU C compiler,
In the author's experience, most (if not all) of the time, the Sun Studio compiler produces better (that is, faster) code than that generated by Now that we've explored the reasons why we would choose Solaris as our primary development platform, let's explore how to actually go about doing so. Building Software on the Solaris Platform
To successfully build software using the Solaris OS, we must first ensure that all the tools we need are installed on our development machine. This means that when we install the Solaris OS, we must select at least the "Developer" metacluster. (The "Full" or "Full + OEM" metaclusters, being supersets of the Developer metacluster, will also work and are probably the best option for people new to the Solaris OS.) An optional (but highly recommended) step is to install the Sun Studio 11 compilers and tools.
The next step is to make sure that our PATH is correctly set:
One problem that people new to the Solaris OS sometimes come across is the inclusion of
With the right software installed, and our PATH appropriately set, we're ready to start building programs. A program called
The rules and dependencies used to build our program are described in a file called
The file
Let's look at a few examples, using the simple counter program shown in the following:
Example: Building With Sun's Compiler and
Our first example runs Sun's
Example: Building With Sun's Compiler and
The next example runs GNU's version of make,
Notice that even though the arguments to
A detailed look at
Example: Building With
Our final example sets the
Notice that this time, Linking With Libraries
Many programs, especially those that are more than moderate in size and complexity, link with libraries other than the default C library. These libraries either come with the Solaris OS, or are third-party libraries installed by the system administrator (be they commercially supplied, downloaded from places like Blastwave.org or Sunfreeware.com, or compiled locally).
We link with these libraries, which are also called shared objects, by passing the name of the library to the compiler with the
The correct place for these libraries to be installed is a library-specific location under
The problem with
We should point out that there is one legitimate use of Summary
This article has described why developers (both commercial and open-source) should choose Solaris as their platform of choice, for both development and deployment. The reasons include:
We also described how to build software on the Solaris platform, using both Sun Studio compilers and Recommended Reading
The author's book, Solaris Systems Programming, published 2005, is considered essential for readers developing Solaris applications. Many books in the Solaris 10 Software Developer Collection are also worth reading or at least being aware of. Bibliography
McDougall, Richard; Mauro, Jim; and Gregg, Brendan. Solaris Performance and Tools, ISBN 0-13-156819-1. Prentice Hall PTR, 2007. Oram, Andrew, and Talbott, Steve. Managing Projects with make, ISBN 0-937175-90-0. Sebastopol, Calif.: O'Reilly and Associates, 1991. Solaris Modular Debugger Guide. Sun Microsystems, 2002. Teer, Rich. Solaris Systems Programming, ISBN 0-201-75039-2. Prentice Hall PTR, 2005. About the Author
Rich Teer is an independent Solaris consultant who has been an active member of the Solaris community for more than 10 years. He is the author of the best-selling Sun Microsystems Press book, Solaris Systems Programming, and numerous Solaris OS-related articles. He was a member of the OpenSolaris pilot program and currently serves on the OpenSolaris Community Advisory Board (CAB). Rich lives in Kelowna, British Columbia, with his wife, Jenny. His web site can be found at http://www.rite-group.com/rich. | |||||||||||||||||||||
|
| ||||||||||||