Sun Studio 12: C++ User's Guide

A.2.30 –G

Build a dynamic shared library instead of an executable file.

All source files specified in the command line are compiled with -xcode=pic13 by default.

When building a shared library that uses templates, it is necessary in most cases to include in the shared library those template functions that are instantiated in the template data base. Using this option automatically adds those templates to the shared library as needed.

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.

When you create a shared object, all the object files compiled with -xarch=v9, must also be compiled with an explicit -xcode value as recommended in A.2.116 –xcode=a.

A.2.30.1 Interactions

The following options are passed to the linker if– c (the compile-only option) is not specified:

Warnings

Do not use ld -G to build shared libraries; use CC -G. The CC driver automatically passes several options to ld that are needed for C++.

When you use the -G option, the compiler does not pass any default -l options to ld. If you want the shared library to have a dependency on another shared library, you must pass the necessary -l option on the command line. For example, if you want the shared library to be dependent upon libCrun, you must pass -lCrun on the command line.

See also

-dy, -Kpic, -xcode=pic13, –ztext, ld(1) man page, 16.3 Building Dynamic (Shared) Libraries.