Sun Studio 12: C++ User's Guide

A.2.4 –Bbinding

Specifies whether a library binding for linking is symbolic, dynamic (shared), or static (nonshared).

You can use the –B option several times on a command line. This option is passed to the linker, ld.


Note –

Many system libraries are only available as dynamic libraries in the Solaris 64-bit compilation environment. Therefore, do not use -Bstatic as the last toggle on the command line.


A.2.4.1 Values

binding must be one of the following:

Value 

Meaning  

dynamic

Directs the link editor to look for liblib.so (shared) files, and if they are not found, to look for liblib.a (static, nonshared) files. Use this option if you want shared library bindings for linking.

static

Directs the link editor to look only for liblib.a (static, nonshared) files. Use this option if you want nonshared library bindings for linking.

symbolic

Forces symbols to be resolved within a shared library if possible, even when a symbol is already defined elsewhere. 

See the ld(1) man page.

(No space is allowed between –B and the binding value.)

Defaults

If -B is not specified, –Bdynamic is assumed.

Interactions

To link the C++ default libraries statically, use the –staticlib option.

The -Bstatic and -Bdynamic options affect the linking of the libraries that are provided by default. To ensure that the default libraries are linked dynamically, the last use of –B should be –Bdynamic.

In a 64-bit environment, many system libraries are available only as shared dynamic libraries. These include libm.so and libc.so (libm.a and libc.a are not provided). As a result, -Bstatic and -dn may cause linking errors in 64-bit Solaris operating systems. Applications must link with the dynamic libraries in these cases.

Examples

The following compiler command links libfoo.a even if libfoo.so exists; all other libraries are linked dynamically:


example% CC a.o –Bstatic –lfoo –Bdynamic

Warnings

Never use -Bsymbolic with programs containing C++ code, use linker map files instead.

With -Bsymbolic, references in different modules can bind to different copies of what is supposed to be one global object.

The exception mechanism relies on comparing addresses. If you have two copies of something, their addresses won’t compare equal, and the exception mechanism can fail because the exception mechanism relies on comparing what are supposed to be unique addresses.

If you compile and link in separate steps and are using the -Bbinding option, you must include the option in the link step.

See also

–nolib, –staticlib, ld(1), 12.5 Statically Linking Standard Libraries, Linker and Libraries Guide