Gentoo Wiki


This article is part of the HOWTO series.
Installation Kernel & Hardware Networks Portage Software System X Server Gaming Non-x86 Emulators Misc



Sun Studio 12 software provides a comprehensive, productive environment for developing applications for the Linux operating system. The current Sun Studio 12 software delivers C, C++, and Fortran-95 compilers and tools for the Linux OS community for evaluation on x64 (AMD64) and x86-based systems. The integrated developer environment (IDE) includes a graphical debugger, performance analysis tools, and X-Designer GUI builder.

Sun Studio 12 software can help you achieve higher system throughput with multithreaded applications. You can build these powerful applications using the OpenMP v2.5 application programming interface (API) with C, C++, and Fortran-95 code, along with an improved debugger and performance analysis tools. Sun Studio 12 provides a robust range of support for application parallelism, including:

Assess the performance of your program, from algorithm changes down to hardware system counters, with one tool that correlates your source code to actual machine execution. Tune your code to maximize application performance with Sun Studio 12 software's sophisticated Performance Analysis Tools.

Downloading the tarfiles and installing the Sun Studio 12 software

Prior to download Sun Studio 12 tarfiles, you are required to register as a SDN member. SDN members can download a free, full-license copy of Sun Studio 12 from the web-page:

Follow link "Free download", and then select "Option 2: Download Product Tarfile". After successful login as a SDN member, download single tarfile:


You don't need the second tarfile contained Sun Studio System Preparation Tool because a Gentoo Linux installation brings all needed components to run Sun Studio compilers.

Create directory /opt/sun and unpack downloaded archive with Sun Studio 12 to this directory:

   # cd /opt/sun
   # bzcat <download_dir>/SunStudio12-linux-x86-200705-ii.tar.bz2 | tar -xf -

See contents of the directory /opt/sun:

   # ls /opt/sun
   SS12_README.txt   lib   netbeans-5.5.1   sunstudio12

Using Sun Studio 12 compilers

Because the Sun Studio 12 software product components and man pages are not installed into the system directories /usr/bin/ and /usr/share/man, you might want to change your PATH and MANPATH environment variables to enable use of the Sun Studio 12 software.

   export PATH=/opt/sun/sunstudio12/bin:$PATH
   export MANPATH=/opt/sun/sunstudio12/man:$MANPATH

The name of Sun C compiler binary is cc.
The name of Sun C++ compiler binary is CC.
The name of Sun Fortran-95 compiler binary is f95.

Sun Studio 12 compilers and Portage

To use Sun Studio 12 compilers with Portage, you should set new definitions of the environment variables CC and CXX. Following Gentoo way, create a file 06sun in the directory /etc/env.d and put such definitions to the file:

File: 06sun

Sun Studio 12 compilers have their own set of flags that are different from GCC flags. So, to avoid warning messages on unknown flags, the environment variables CFLAGS and CXXFLAGS should be also redefined. Modify values of the environment variables in the file /etc/make.conf:

File: /etc/make.conf
 GCC_CFLAGS="-O2 -march=i686 -pipe"

This is just a simple example where the strings with compilation flags are empty. Put appropriate flags to the definitions if it's needed.

Sun C/C++ compilation flags

This is a short list of compilation flags derived from Sun Studio 12 man pages:


Causes each invoked tool to print its version information on the standard error output.


Displays a brief description of each compiler flag.

-On (the same as -xOn)

Specifies optimization level (n). (Note the uppercase letter O, followed by a digit 1, 2, 3, 4, or 5)
Generally, the higher the level of optimization with which a program is compiled, the better runtime performance obtained. However, higher optimization levels may result in increased compilation time and larger executable files.
There are five levels that you can use with -xOn. The actual optimizations performed by the compiler at each level may change with each compiler release.
  • -xO1 - Preloads arguments from memory, cross-jumping (tail-merging), as well as the single pass of the default optimization.
  • -xO2 - Schedules both high- and low-level instructions and performs improved spill analysis, loop memory-reference elimination, register lifetime analysis, enhanced register allocation, and elimination of global common subexpressions.
  • -xO3 - Performs loop strength reduction, induction variable elimination, as well as the optimization done by -xO2.
  • -xO4 - Performs automatic inlining of functions contained in the same file in addition to performing -xO3 optimizations. This automatic inlining usually improves execution speed, but sometimes makes it worse. In general, this level results in increased code size.
  • -xO5 - Generates the highest level of optimization. Uses optimization algorithms that take more compilation time or that do not have as high a certainty of improving execution time. Some of these include generating local calling convention entry points for exported functions, further optimizing spill code and adding analysis to improve instruction scheduling.


Produces additional symbol table information for dbx and the Performance Analyzer analyzer.
Debugging with -g does not suppress -xOn, but -xOn limits -g in certain ways. For example, the optimization options reduce the utility of debugging so that you cannot display variables from dbx, but you can still use the dbx where command to get a symbolic traceback. For more information, see Debugging a Program With dbx.


Specifies the memory model for the compiled binary object. Use -m32 to create 32-bit executables and shared libraries. Use -m64 to create 64-bit executables and shared libraries.
The ILP32 memory model (32-bit int, long, pointer data types) is the default on Linux platforms that are not 64-bit enabled. The LP64 memory model (64-bit long, pointer data types) is the default on Linux platforms that are 64-bit enabled. -m64 is permitted only on platforms that are enabled for the LP64 model.


Specifies the target architecture instruction set (ISA). If -xarch=isa is not specified, the defaults is -xarch=386 on x86/x64 platforms
Values specific to x86 platforms:
  • 386 - Limits the instruction set to the Intel 32-bit 386/486 architecture.
  • pentium_pro - Limits the instruction set to the 32-bit pentium_pro architecture.
  • sse - Adds the SSE instruction set to the pentium_pro instruction set.
  • sse2 - Adds the SSE2 instruction set to the pentium_pro instruction set.
  • pentium_proa - Adds the AMD extensions (3DNow!, 3DNow! extensions, and MMX extensions) to the pentium_pro architecture.
  • ssea - Adds the AMD extensions (3DNow!, 3DNow! extensions, and MMX extensions) to the 32-bit SSE architecture.
  • sse2a - Adds the AMD extensions (3DNow!, 3DNow! extensions, and MMX extensions) to the SSE2 architecture.
  • sse3 - Adds the SSE3 instruction set to SSE2 instruction set.


Specifies the target processor for use by the optimizer.
The -xchip values for x86 platforms are:
  • generic - Optimize for most x86 platforms.
  • native - Optimize for this host processor.
  • 386 - Optimize for the 386 architecture.
  • 486 - Optimize for the 486 architecture.
  • opteron - Optimize for the AMD Opteron processor.
  • pentium - Optimize for the pentium architecture.
  • pentium_pro - Optimize for the pentium_pro architecture.
  • pentium3 - Optimize for Pentium 3 style processor
  • pentium4 - Optimize for Pentium 4 style processor


Produces position-independent code. Use this option to compile source files when building a shared library. Each reference to a global datum is generated as a dereference of a pointer in the global offset table. Each function call is generated in pc-relative addressing mode through a procedure linkage table.


Build a dynamic shared library instead of an executable file;
If you are creating a shared object by specifying -G along with other compiler options that must be specified at both compile time and link time, make sure that those same options are also specified at both compile time and link time when you link with the resulting shared object.


Specifies the degree of conformance to the ISO C standard. The value of -xc99 affects which version of the ISO C standard the -X option applies.


The -xc99 flag controls compiler recognition of the implemented features from the C99 standard (ISO/IEC 9899:1999, Programming Language - C).
If you specify -xc99 without any values, the option is set to -xc99=all.

Sun Studio 12 Integrated Development Environment (IDE)

The new Sun Studio IDE is based on NetBeans 5.5.1 and adds many new features. It supports C and C++ projects, and includes appropriate project templates for applications, dynamic and static libraries, and projects with existing code. The IDE includes a C and C++ class browser. The powerful language-aware built-in editor supports code completion.

NetBeans 5.5.1 is delivered in the same archive that contains Sun Studio 12 software.

To run Sun Studio 12 IDE, Java SE 1.5 or 1.6 should be installed on your system. The minimum requirement is JDK 1.5.0_09. If the JDK software is not installed, you can install the JDK software included from Gentoo portage by running the command:

   # emerge sun-jdk

Check the version of JDK by the command:

   # java-config -L
   The following VMs are available for generation-2:
   *)      Sun JDK [sun-jdk-1.5]

Before using the Sun Studio 12 Integrated Development Environment (IDE), read the Integrated Development Environment (IDE) readme, which is available through the documentation index page at the file /opt/sun/sunstudio12/docs/index.html.

To start Sun Studio IDE, run the command:


or just:


if you set the path to Sun Studio binaries to PATH environment variable.


Sun Studio 12 Home Page
Sun Studio 12 Documentation
Sun Studio 12 Documentation Collection
Retrieved from ""

Last modified: Fri, 05 Sep 2008 10:51:00 +0000 Hits: 4,581