-static (-qstaticlink)

Category

Linking

Pragma equivalent

None.

Purpose

Controls whether static or shared runtime libraries are linked into an application.

Syntax

Read syntax diagramSkip visual syntax diagram
>>- -static--+----------+--------------------------------------><
             '- -libgcc-'   

Read syntax diagramSkip visual syntax diagram
>>- -shared-libgcc---------------------------------------------><

Read syntax diagramSkip visual syntax diagram
        .-nostaticlink-.                          
>>- -q--+-staticlink---+--+-------------------+----------------><
                          |    .-:----------. |   
                          |    V            | |   
                          '-=----+-libgcc-+-+-'   
                                 '-xllibs-'       

The following table shows the equivalent usage between different format of options for specifying the linkage of shared and nonshared libraries.

Table 1. Option equivalence mapping
Equivalent option Meaning
-static or -qstaticlink Build a static object and prevent linking with shared libraries. Every library that is linked to must be a static library.
-shared-libgcc or -qnostaticlink=libgcc Link with the shared version of libgcc.
-static-libgcc or -qstaticlink=libgcc Link with the static version of libgcc.

Defaults

-qnostaticlink

Parameters

libgcc
  • When you specify -shared-libgcc, the compiler links the shared version of libgcc.
  • When you specify -static-libgcc, the compiler links the static version of libgcc.
xllibs
  • When you specify xllibs with -qnostaticlink, the compiler links the shared version of the XL compiler libraries.
  • When you specify xllibs with -qstaticlink, the compiler links the static version of the XL compiler libraries.
The xllibs suboption is available only for the -qstaticlink and -qnostaticlink options.

Usage

When you specify -static without suboptions, only static libraries are linked with the object file.

When you specify -qnostaticlink without suboptions, shared libraries are linked with the object file.

When compiler options are combined, conflicts might occur. The following table describes the resolutions of the conflicting compiler options.

Table 2. Examples of conflicting compiler options and resolutions
Options combination examples Resolution result Compiler behavior
-qnostaticlink -static-libgcc Equivalent to -static-libgcc If you first specify -qnostaticlink without suboptions and then specify -static or -qstaticlink with or without suboptions, -qnostaticlink is overridden. All libraries are linked statically.
-qnostaticlink -qstaticlink=xllibs Equivalent to -qstaticlink=xllibs
-static-libgcc -qnostaticlink Equivalent to -qnostaticlink If you specify -static with or without suboptions followed by -qnostaticlink without suboptions, -qnostaticlink takes effect and shared libraries are linked.
-static -shared-libgcc Equivalent to -static If you specify -static without suboptions followed by -shared-libgcc or -qnostaticlink with suboptions, -static takes effect and only static libraries are linked with the object file.
-static -qnostaticlink=libgcc

:xllibs

Equivalent to -static
-shared-libgcc -static Equivalent to -static If you first specify -shared-libgcc with suboptions and then specify -static without suboptions, -static takes effect and all libraries are linked statically.
Notes:
  • If a runtime library is linked in statically while its message catalog is not installed on the system, messages are issued with message numbers only, and no message text is shown.
  • If a shared library or a dynamically linked application is supposed to throw or catch exceptions, you must link it with the shared libgcc by using -shared-libgcc.

Predefined macros

None.

Related information



Voice your opinion on getting help information Ask IBM compiler experts a technical question in the IBM XL compilers forum Reach out to us